@@ -31,7 +31,8 @@ def __init__(self, size_or_data):
3131 raise MemoryError ("Unable to allocate memory for filter" )
3232 else :
3333 data = list (map (lambda x : c_ulonglong ((hash (x ))).value , data ))
34- lib .xor8_buffered_populate (data , len (data ), self .__filter )
34+ if not lib .xor8_buffered_populate (data , len (data ), self .__filter ):
35+ raise ValueError ("Unable to populate the filter" )
3536
3637 def __repr__ (self ):
3738 return "Xor8 object with size(in bytes):{}" .format (self .size_in_bytes ())
@@ -125,7 +126,8 @@ def __init__(self, size_or_data):
125126 raise MemoryError ("Unable to allocate memory for filter" )
126127 else :
127128 data = list (map (lambda x : c_ulonglong ((hash (x ))).value , data ))
128- lib .xor16_buffered_populate (data , len (data ), self .__filter )
129+ if not lib .xor16_buffered_populate (data , len (data ), self .__filter ):
130+ raise ValueError ("Unable to populate the filter" )
129131
130132 def __repr__ (self ):
131133 """
@@ -224,7 +226,8 @@ def __init__(self, size_or_data):
224226 raise MemoryError ("Unable to allocate memory for filter" )
225227 else :
226228 data = list (map (lambda x : c_ulonglong ((hash (x ))).value , data ))
227- lib .binary_fuse8_populate (data , len (data ), self .__filter )
229+ if not lib .binary_fuse8_populate (data , len (data ), self .__filter ):
230+ raise ValueError ("Unable to populate the filter" )
228231
229232 def __repr__ (self ):
230233 """
@@ -257,11 +260,15 @@ def __del__(self):
257260 def populate (self , data : list ):
258261 """
259262 Set the data of the filter. You may use this method to add data after
260- allocating the filter with an integer size. The sizes should match.
261- You can reuse a filter with new data (i.e., call populate several times)
262- as long as the size remains a constant .
263+ allocating the filter with an integer size. If the number of items
264+ differs from the allocated size, the filter is reallocated.
265+ You can reuse a filter with new data (i.e., call populate several times) .
263266 """
264267 data = list (map (lambda x : c_ulonglong ((hash (x ))).value , data ))
268+ if len (data ) != self .__filter .Size :
269+ lib .binary_fuse8_free (self .__filter )
270+ if not lib .binary_fuse8_allocate (len (data ), self .__filter ):
271+ raise MemoryError ("Unable to allocate memory for filter" )
265272 return lib .binary_fuse8_populate (data , len (data ), self .__filter )
266273
267274 def contains (self , item ):
@@ -323,7 +330,8 @@ def __init__(self, size_or_data):
323330 raise MemoryError ("Unable to allocate memory for filter" )
324331 else :
325332 data = list (map (lambda x : c_ulonglong ((hash (x ))).value , data ))
326- lib .binary_fuse16_populate (data , len (data ), self .__filter )
333+ if not lib .binary_fuse16_populate (data , len (data ), self .__filter ):
334+ raise ValueError ("Unable to populate the filter" )
327335
328336 def __repr__ (self ):
329337 """
@@ -356,11 +364,15 @@ def __del__(self):
356364 def populate (self , data : list ):
357365 """
358366 Set the data of the filter. You may use this method to add data after
359- allocating the filter with an integer size. The sizes should match.
360- You can reuse a filter with new data (i.e., call populate several times)
361- as long as the size remains a constant .
367+ allocating the filter with an integer size. If the number of items
368+ differs from the allocated size, the filter is reallocated.
369+ You can reuse a filter with new data (i.e., call populate several times) .
362370 """
363371 data = list (map (lambda x : c_ulonglong ((hash (x ))).value , data ))
372+ if len (data ) != self .__filter .Size :
373+ lib .binary_fuse16_free (self .__filter )
374+ if not lib .binary_fuse16_allocate (len (data ), self .__filter ):
375+ raise MemoryError ("Unable to allocate memory for filter" )
364376 return lib .binary_fuse16_populate (data , len (data ), self .__filter )
365377
366378 def contains (self , item ):
0 commit comments