@@ -50,8 +50,7 @@ public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
50
50
* Creates a new bitmap from a pointer of uint32_t integers
51
51
*/
52
52
public init ( values: [ UInt32 ] ) {
53
- let ptr : UnsafeMutablePointer = UnsafeMutablePointer ( mutating: values)
54
- self . ptr = croaring. roaring_bitmap_of_ptr ( values. count, ptr) !
53
+ self . ptr = croaring. roaring_bitmap_of_ptr ( values. count, values) !
55
54
}
56
55
57
56
public required init ( arrayLiteral: Element ... ) {
@@ -186,18 +185,14 @@ public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
186
185
}
187
186
188
187
/**
189
- * Inplace version of roaring_bitmap_or, modifies x1. TDOO: decide whether x1 ==
190
- *x2 ok
191
- *
188
+ * Inplace version of roaring_bitmap_or, modifies x1.
192
189
*/
193
190
public func formUnion( _ x: RoaringBitmap ) {
194
191
croaring. roaring_bitmap_or_inplace ( self . ptr, x. ptr)
195
192
196
193
}
197
194
/**
198
- * Inplace version of roaring_bitmap_or, modifies x1. TDOO: decide whether x1 ==
199
- *x2 ok
200
- *
195
+ * Inplace version of roaring_bitmap_or, modifies x1.
201
196
*/
202
197
public static func |= ( left: RoaringBitmap , right: RoaringBitmap ) {
203
198
left. formUnion ( right)
@@ -207,16 +202,14 @@ public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
207
202
* Compute the union of 'number' bitmaps. See also roaring_bitmap_or_many_heap.
208
203
* Caller is responsible for freeing the
209
204
* result.
210
- *
211
205
*/
212
206
public func unionMany( _ xs: [ RoaringBitmap ] ) -> RoaringBitmap {
213
- var ptrArray : [ UnsafePointer < roaring_bitmap_t > ? ] = [ ]
214
- ptrArray . append ( self . ptr)
215
- for x in xs {
216
- ptrArray . append ( x . ptr)
207
+ let ptr = UnsafeMutablePointer < Optional < UnsafePointer< roaring_bitmap_t>>> . allocate ( capacity : xs . count + 1 )
208
+ ptr [ 0 ] = UnsafePointer < roaring_bitmap_t > ( self . ptr)
209
+ for (index , bitmap ) in xs. enumerated ( ) {
210
+ ptr [ index + 1 ] = UnsafePointer < roaring_bitmap_t > ( bitmap . ptr)
217
211
}
218
- let ptrArrayPtr : UnsafeMutablePointer = UnsafeMutablePointer ( mutating: ptrArray)
219
- return RoaringBitmap ( ptr: croaring. roaring_bitmap_or_many ( ptrArray. count, ptrArrayPtr) )
212
+ return RoaringBitmap ( ptr: croaring. roaring_bitmap_or_many ( xs. count + 1 , ptr) )
220
213
221
214
}
222
215
@@ -228,14 +221,12 @@ public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
228
221
*
229
222
*/
230
223
public func unionManyHeap( _ xs: [ RoaringBitmap ] ) -> RoaringBitmap {
231
- var ptrArray : [ UnsafePointer < roaring_bitmap_t > ? ] = [ ]
232
- ptrArray . append ( self . ptr)
233
- for x in xs {
234
- ptrArray . append ( x . ptr)
224
+ let ptr = UnsafeMutablePointer < Optional < UnsafePointer< roaring_bitmap_t>>> . allocate ( capacity : xs . count + 1 )
225
+ ptr [ 0 ] = UnsafePointer < roaring_bitmap_t > ( self . ptr)
226
+ for (index , bitmap ) in xs. enumerated ( ) {
227
+ ptr [ index + 1 ] = UnsafePointer < roaring_bitmap_t > ( bitmap . ptr)
235
228
}
236
- let ptrArrayPtr : UnsafeMutablePointer = UnsafeMutablePointer ( mutating: ptrArray)
237
- return RoaringBitmap ( ptr: croaring. roaring_bitmap_or_many_heap ( UInt32 ( ptrArray. count) , ptrArrayPtr) )
238
-
229
+ return RoaringBitmap ( ptr: croaring. roaring_bitmap_or_many_heap ( UInt32 ( xs. count + 1 ) , ptr) )
239
230
}
240
231
241
232
/**
@@ -278,14 +269,12 @@ public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
278
269
*
279
270
*/
280
271
public func symmetricDifferenceMany( _ xs: [ RoaringBitmap ] ) -> RoaringBitmap {
281
- var ptrArray : [ UnsafePointer < roaring_bitmap_t > ? ] = [ ]
282
- for x in xs {
283
- ptrArray. append ( x. ptr)
272
+ let ptr = UnsafeMutablePointer< Optional< UnsafePointer< roaring_bitmap_t>>> . allocate( capacity: xs. count + 1 )
273
+ ptr [ 0 ] = UnsafePointer < roaring_bitmap_t > ( self . ptr)
274
+ for (index, bitmap) in xs. enumerated ( ) {
275
+ ptr [ index + 1 ] = UnsafePointer < roaring_bitmap_t > ( bitmap. ptr)
284
276
}
285
- ptrArray. append ( self . ptr)
286
- let ptrArrayPtr : UnsafeMutablePointer = UnsafeMutablePointer ( mutating: ptrArray)
287
- return RoaringBitmap ( ptr: croaring. roaring_bitmap_xor_many ( ptrArray. count, ptrArrayPtr) )
288
-
277
+ return RoaringBitmap ( ptr: croaring. roaring_bitmap_xor_many ( xs. count + 1 , ptr) )
289
278
}
290
279
291
280
@@ -493,8 +482,7 @@ public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
493
482
*
494
483
*/
495
484
public func addMany( values: [ UInt32 ] ) {
496
- let ptr : UnsafeMutablePointer = UnsafeMutablePointer ( mutating: values)
497
- croaring. roaring_bitmap_add_many ( self . ptr, values. count, ptr)
485
+ croaring. roaring_bitmap_add_many ( self . ptr, values. count, values)
498
486
}
499
487
500
488
/**
@@ -680,18 +668,16 @@ public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
680
668
* Returns how many bytes were written which should be
681
669
* roaring_bitmap_size_in_bytes(ra).
682
670
*/
683
- public func serialize( buffer: [ Int8 ] ) -> size_t {
684
- let ptr : UnsafeMutablePointer = UnsafeMutablePointer ( mutating: buffer)
685
- return croaring. roaring_bitmap_serialize ( self . ptr, ptr)
671
+ public func serialize( buffer: inout [ Int8 ] ) -> size_t {
672
+ return croaring. roaring_bitmap_serialize ( self . ptr, & buffer)
686
673
}
687
674
688
675
/** use with roaring_bitmap_serialize
689
676
* see roaring_bitmap_portable_deserialize if you want a format that's
690
677
* compatible with Java and Go implementations
691
678
*/
692
679
public static func deserialize( buffer: [ Int8 ] ) -> RoaringBitmap {
693
- let bufferPtr : UnsafeMutablePointer = UnsafeMutablePointer ( mutating: buffer)
694
- return RoaringBitmap ( ptr: croaring. roaring_bitmap_deserialize ( bufferPtr) !)
680
+ return RoaringBitmap ( ptr: croaring. roaring_bitmap_deserialize ( buffer) !)
695
681
}
696
682
697
683
/**
@@ -713,8 +699,7 @@ public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
713
699
* call roaring_bitmap_portable_deserialize_safe.
714
700
*/
715
701
public static func portableDeserialize( buffer: [ Int8 ] ) -> RoaringBitmap {
716
- let bufferPtr : UnsafeMutablePointer = UnsafeMutablePointer ( mutating: buffer)
717
- return RoaringBitmap ( ptr: croaring. roaring_bitmap_portable_deserialize ( bufferPtr) !)
702
+ return RoaringBitmap ( ptr: croaring. roaring_bitmap_portable_deserialize ( buffer) !)
718
703
}
719
704
720
705
/**
@@ -725,8 +710,7 @@ public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
725
710
* In case of failure, a null pointer is returned.
726
711
*/
727
712
public static func portableDeserializeSafe( buffer: [ Int8 ] , maxbytes: size_t ) -> RoaringBitmap {
728
- let bufferPtr : UnsafeMutablePointer = UnsafeMutablePointer ( mutating: buffer)
729
- return RoaringBitmap ( ptr: croaring. roaring_bitmap_portable_deserialize_safe ( bufferPtr, maxbytes) !)
713
+ return RoaringBitmap ( ptr: croaring. roaring_bitmap_portable_deserialize_safe ( buffer, maxbytes) !)
730
714
}
731
715
732
716
/**
@@ -737,8 +721,7 @@ public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
737
721
* https://github.com/RoaringBitmap/RoaringFormatSpec
738
722
*/
739
723
public static func portableDeserializeSize( buffer: [ Int8 ] , maxbytes: size_t ) -> size_t {
740
- let bufferPtr : UnsafeMutablePointer = UnsafeMutablePointer ( mutating: buffer)
741
- return croaring. roaring_bitmap_portable_deserialize_size ( bufferPtr, maxbytes)
724
+ return croaring. roaring_bitmap_portable_deserialize_size ( buffer, maxbytes)
742
725
}
743
726
744
727
@@ -760,11 +743,11 @@ public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
760
743
* roaring_bitmap_portable_size_in_bytes(ra). See format specification at
761
744
* https://github.com/RoaringBitmap/RoaringFormatSpec
762
745
*/
763
- public func portableSerialize( buffer: [ Int8 ] ) -> size_t {
764
- let bufferPtr : UnsafeMutablePointer = UnsafeMutablePointer ( mutating: buffer)
765
- return croaring. roaring_bitmap_portable_serialize ( self . ptr, bufferPtr)
746
+ public func portableSerialize( buffer: inout [ Int8 ] ) -> size_t {
747
+ return croaring. roaring_bitmap_portable_serialize ( self . ptr, & buffer)
766
748
}
767
749
750
+
768
751
/**
769
752
* If the size of the roaring bitmap is strictly greater than rank, then this
770
753
function returns true and set the value to the the given rank.
@@ -862,7 +845,7 @@ public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
862
845
}
863
846
return Int ( truncatingIfNeeded: hash)
864
847
}
865
-
848
+
866
849
public func hash( into hasher: inout Hasher ) {
867
850
for i in self {
868
851
i. hash ( into: & hasher)
0 commit comments