1 /*******************************************************************************
2 
3     Bindings for Elastic Binary Trees library's generic operations and
4     structures.
5 
6     This module contains the D binding of the library functions of ebtree.h.
7     Please consult the original header documentation for details.
8 
9     You need to have the library installed and link with -lebtree.
10 
11     Copyright:
12         Copyright (c) 2009-2016 dunnhumby Germany GmbH.
13         All rights reserved.
14 
15     License:
16         Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
17         Alternatively, this file may be distributed under the terms of the Tango
18         3-Clause BSD License (see LICENSE_BSD.txt for details).
19 
20         Bear in mind this module provides bindings to an external library that
21         has its own license, which might be more restrictive. Please check the
22         external library license to see which conditions apply for linking.
23 
24 *******************************************************************************/
25 
26 module ocean.util.container.ebtree.c.ebtree;
27 
28 
29 import ocean.meta.types.Qualifiers;
30 
31 
32 /// See original's library documentation for details.
33 alias void eb_troot_t;
34 
35 /// See original's library documentation for details.
36 struct eb_root
37 {
38     enum BITS          = 1;
39     enum BRANCHES      = (1 << BITS);
40 
41     enum RGHT   = 1;
42     enum NORMAL = cast(eb_troot_t*)0;
43     enum UNIQUE = cast(eb_troot_t*)1;
44 
45     eb_troot_t*[BRANCHES] b;
46 
47     bool is_empty ( )
48     {
49         return !!eb_is_empty(&this);
50     }
51 
52     /***************************************************************************
53 
54         Tells whether this tree is configured so that the `eb*_insert` functions
55         allow adding unique nodes only or if they allow adding duplicates.
56 
57         Returns:
58             true if only unique nodes are added for this tree or false if
59             duplicates can be added.
60 
61     ***************************************************************************/
62 
63     bool unique ( )
64     {
65         return this.b[RGHT] is UNIQUE;
66     }
67 
68     /***************************************************************************
69 
70         Configures this tree so that the `eb*_insert` functions either allow
71         adding unique nodes only or allow adding duplicates.
72 
73         This configuration can be changed at any time and affects subsequent
74         `eb*_insert` function calls.
75 
76         Params:
77             enable = true: only allow unique nodes;
78                      false: allow adding duplicates
79 
80         Returns:
81             enable
82 
83     ***************************************************************************/
84 
85     bool unique ( bool enable )
86     {
87         this.b[RGHT] = enable? UNIQUE : NORMAL;
88         return enable;
89     }
90 }
91 
92 /// See original's library documentation for details.
93 struct eb_node
94 {
95     eb_root     branches;
96     eb_troot_t* node_p,
97                 leaf_p;
98     short       bit;
99     short       pfx;
100 
101     alias .eb_first first;
102 
103     alias .eb_last last;
104 
105     typeof(&this) prev( )
106     {
107         return eb_prev(&this);
108     }
109 
110     typeof(&this) next ( )
111     {
112         return eb_next(&this);
113     }
114 
115     typeof(&this) prev_unique ( )
116     {
117         return eb_prev_unique(&this);
118     }
119 
120     typeof(&this) next_unique ( )
121     {
122         return eb_next_unique(&this);
123     }
124 
125     void remove ( )
126     {
127         eb_delete(&this);
128     }
129 };
130 
131 
132 extern (C):
133 
134 /// See original's library documentation for details.
135 int eb_is_empty(eb_root* root);
136 
137 /// See original's library documentation for details.
138 eb_node* eb_first(eb_root* root);
139 
140 /// See original's library documentation for details.
141 eb_node* eb_last(eb_root* root);
142 
143 /// See original's library documentation for details.
144 eb_node* eb_prev(eb_node* node);
145 
146 /// See original's library documentation for details.
147 eb_node* eb_next(eb_node* node);
148 
149 /// See original's library documentation for details.
150 eb_node* eb_prev_unique(eb_node* node);
151 
152 /// See original's library documentation for details.
153 eb_node* eb_next_unique(eb_node* node);
154 
155 /// See original's library documentation for details.
156 void eb_delete(eb_node* node);
157 
158 /// See original's library documentation for details.
159 int equal_bits(char* a, char* b, int ignore, int len);
160 
161 /// See original's library documentation for details.
162 int check_bits(char* a, char* b, int skip, int len);
163 
164 /// See original's library documentation for details.
165 int string_equal_bits(char* a, char* b, int ignore);
166 
167 /// See original's library documentation for details.
168 int cmp_bits(char* a, char* b, uint pos);
169 
170 /// See original's library documentation for details.
171 int get_bit(char* a, uint pos);