summary refs log tree commit diff stats
path: root/lib/pure/collections/intsets.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/collections/intsets.nim')
-rw-r--r--lib/pure/collections/intsets.nim43
1 files changed, 22 insertions, 21 deletions
diff --git a/lib/pure/collections/intsets.nim b/lib/pure/collections/intsets.nim
index f1e67fc0e..5d9c3f445 100644
--- a/lib/pure/collections/intsets.nim
+++ b/lib/pure/collections/intsets.nim
@@ -1,6 +1,6 @@
 #
 #
-#            Nimrod's Runtime Library
+#            Nim's Runtime Library
 #        (c) Copyright 2012 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
@@ -9,7 +9,7 @@
 
 ## The ``intsets`` module implements an efficient int set implemented as a
 ## sparse bit set.
-## **Note**: Since Nimrod currently does not allow the assignment operator to
+## **Note**: Since Nim currently does not allow the assignment operator to
 ## be overloaded, ``=`` for int sets performs some rather meaningless shallow
 ## copy; use ``assign`` to get a deep copy.
 
@@ -17,7 +17,7 @@ import
   os, hashes, math
 
 type
-  TBitScalar = int
+  BitScalar = int
 
 const 
   InitIntSetSize = 8         # must be a power of two!
@@ -25,8 +25,8 @@ const
   BitsPerTrunk = 1 shl TrunkShift # needs to be a power of 2 and
                                   # divisible by 64
   TrunkMask = BitsPerTrunk - 1
-  IntsPerTrunk = BitsPerTrunk div (sizeof(TBitScalar) * 8)
-  IntShift = 5 + ord(sizeof(TBitScalar) == 8) # 5 or 6, depending on int width
+  IntsPerTrunk = BitsPerTrunk div (sizeof(BitScalar) * 8)
+  IntShift = 5 + ord(sizeof(BitScalar) == 8) # 5 or 6, depending on int width
   IntMask = 1 shl IntShift - 1
 
 type
@@ -34,15 +34,16 @@ type
   TTrunk {.final.} = object 
     next: PTrunk             # all nodes are connected with this pointer
     key: int                 # start address at bit 0
-    bits: array[0..IntsPerTrunk - 1, TBitScalar] # a bit vector
+    bits: array[0..IntsPerTrunk - 1, BitScalar] # a bit vector
   
   TTrunkSeq = seq[PTrunk]
-  TIntSet* {.final.} = object ## an efficient set of 'int' implemented as a
-                              ## sparse bit set
+  IntSet* = object ## an efficient set of 'int' implemented as a sparse bit set
     counter, max: int
     head: PTrunk
     data: TTrunkSeq
 
+{.deprecated: [TIntSet: IntSet].}
+
 proc mustRehash(length, counter: int): bool {.inline.} = 
   assert(length > counter)
   result = (length * 2 < counter * 3) or (length - counter < 4)
@@ -50,7 +51,7 @@ proc mustRehash(length, counter: int): bool {.inline.} =
 proc nextTry(h, maxHash: THash): THash {.inline.} = 
   result = ((5 * h) + 1) and maxHash 
 
-proc intSetGet(t: TIntSet, key: int): PTrunk = 
+proc intSetGet(t: IntSet, key: int): PTrunk = 
   var h = key and t.max
   while t.data[h] != nil: 
     if t.data[h].key == key: 
@@ -58,7 +59,7 @@ proc intSetGet(t: TIntSet, key: int): PTrunk =
     h = nextTry(h, t.max)
   result = nil
 
-proc intSetRawInsert(t: TIntSet, data: var TTrunkSeq, desc: PTrunk) = 
+proc intSetRawInsert(t: IntSet, data: var TTrunkSeq, desc: PTrunk) = 
   var h = desc.key and t.max
   while data[h] != nil: 
     assert(data[h] != desc)
@@ -66,7 +67,7 @@ proc intSetRawInsert(t: TIntSet, data: var TTrunkSeq, desc: PTrunk) =
   assert(data[h] == nil)
   data[h] = desc
 
-proc intSetEnlarge(t: var TIntSet) = 
+proc intSetEnlarge(t: var IntSet) = 
   var n: TTrunkSeq
   var oldMax = t.max
   t.max = ((t.max + 1) * 2) - 1
@@ -75,7 +76,7 @@ proc intSetEnlarge(t: var TIntSet) =
     if t.data[i] != nil: intSetRawInsert(t, n, t.data[i])
   swap(t.data, n)
 
-proc intSetPut(t: var TIntSet, key: int): PTrunk = 
+proc intSetPut(t: var IntSet, key: int): PTrunk = 
   var h = key and t.max
   while t.data[h] != nil: 
     if t.data[h].key == key: 
@@ -92,7 +93,7 @@ proc intSetPut(t: var TIntSet, key: int): PTrunk =
   t.head = result
   t.data[h] = result
 
-proc contains*(s: TIntSet, key: int): bool =
+proc contains*(s: IntSet, key: int): bool =
   ## returns true iff `key` is in `s`.  
   var t = intSetGet(s, `shr`(key, TrunkShift))
   if t != nil: 
@@ -101,14 +102,14 @@ proc contains*(s: TIntSet, key: int): bool =
   else: 
     result = false
   
-proc incl*(s: var TIntSet, key: int) = 
+proc incl*(s: var IntSet, key: int) = 
   ## includes an element `key` in `s`.
   var t = intSetPut(s, `shr`(key, TrunkShift))
   var u = key and TrunkMask
   t.bits[`shr`(u, IntShift)] = t.bits[`shr`(u, IntShift)] or
       `shl`(1, u and IntMask)
 
-proc excl*(s: var TIntSet, key: int) = 
+proc excl*(s: var IntSet, key: int) = 
   ## excludes `key` from the set `s`.
   var t = intSetGet(s, `shr`(key, TrunkShift))
   if t != nil: 
@@ -116,7 +117,7 @@ proc excl*(s: var TIntSet, key: int) =
     t.bits[`shr`(u, IntShift)] = t.bits[`shr`(u, IntShift)] and
         not `shl`(1, u and IntMask)
 
-proc containsOrIncl*(s: var TIntSet, key: int): bool = 
+proc containsOrIncl*(s: var IntSet, key: int): bool = 
   ## returns true if `s` contains `key`, otherwise `key` is included in `s`
   ## and false is returned.
   var t = intSetGet(s, `shr`(key, TrunkShift))
@@ -130,14 +131,14 @@ proc containsOrIncl*(s: var TIntSet, key: int): bool =
     incl(s, key)
     result = false
     
-proc initIntSet*: TIntSet =
+proc initIntSet*: IntSet =
   ## creates a new int set that is empty.
   newSeq(result.data, InitIntSetSize)
   result.max = InitIntSetSize-1
   result.counter = 0
   result.head = nil
 
-proc assign*(dest: var TIntSet, src: TIntSet) =
+proc assign*(dest: var IntSet, src: IntSet) =
   ## copies `src` to `dest`. `dest` does not need to be initialized by
   ## `initIntSet`. 
   dest.counter = src.counter
@@ -161,7 +162,7 @@ proc assign*(dest: var TIntSet, src: TIntSet) =
 
     it = it.next
 
-iterator items*(s: TIntSet): int {.inline.} =
+iterator items*(s: IntSet): int {.inline.} =
   ## iterates over any included element of `s`.
   var r = s.head
   while r != nil:
@@ -186,11 +187,11 @@ template dollarImpl(): stmt =
     result.add($key)
   result.add("}")
 
-proc `$`*(s: TIntSet): string =
+proc `$`*(s: IntSet): string =
   ## The `$` operator for int sets.
   dollarImpl()
 
-proc empty*(s: TIntSet): bool {.inline.} =
+proc empty*(s: IntSet): bool {.inline.} =
   ## returns true if `s` is empty. This is safe to call even before
   ## the set has been initialized with `initIntSet`.
   result = s.counter == 0
30787d746ca805949a13c28452aca90af49d'>703430787 ^
7fcbdc6d4 ^
703430787 ^













1d1752cac ^
703430787 ^
1d1752cac ^
703430787 ^



23340695d ^



703430787 ^



1d1752cac ^
703430787 ^

1d1752cac ^
703430787 ^
703430787 ^
1d1752cac ^
703430787 ^

1d1752cac ^
703430787 ^

1d1752cac ^
703430787 ^
1d1752cac ^
703430787 ^

1d1752cac ^
703430787 ^

1d1752cac ^
703430787 ^

1d1752cac ^
703430787 ^
1d1752cac ^
703430787 ^

af792da0b ^
703430787 ^
703430787 ^
af792da0b ^
703430787 ^
04300542d ^

703430787 ^
af792da0b ^
703430787 ^

22dc76a36 ^
703430787 ^

1d1752cac ^
703430787 ^
1d1752cac ^
703430787 ^
af792da0b ^
703430787 ^
632aece19 ^

161f6f722 ^

632aece19 ^







04300542d ^

632aece19 ^











d2b45dbe8 ^
632aece19 ^













d2b45dbe8 ^
632aece19 ^




d2b45dbe8 ^
632aece19 ^









d2b45dbe8 ^
632aece19 ^
af792da0b ^
703430787 ^
af792da0b ^
703430787 ^
04300542d ^

703430787 ^
af792da0b ^
703430787 ^


1d1752cac ^
703430787 ^








1d1752cac ^
703430787 ^
1d1752cac ^
703430787 ^
af792da0b ^
703430787 ^
af792da0b ^
703430787 ^

af792da0b ^
703430787 ^
04300542d ^

703430787 ^
af792da0b ^
703430787 ^


1d1752cac ^
703430787 ^



1d1752cac ^
703430787 ^


af792da0b ^
703430787 ^




1d1752cac ^
703430787 ^

af792da0b ^
703430787 ^






d2b45dbe8 ^

703430787 ^




d2b45dbe8 ^

703430787 ^










d2b45dbe8 ^

703430787 ^
af792da0b ^
632aece19 ^


af792da0b ^





cd83cc81a ^

af792da0b ^

632aece19 ^


af792da0b ^





cd83cc81a ^

af792da0b ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316