Class: CZMQ::FFI::Zhashx
- Inherits:
-
Object
- Object
- CZMQ::FFI::Zhashx
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zhashx.rb
Overview
This class is 100% generated using zproject.
extended generic type-free hash container
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .__new ⇒ Object
-
.comparator_fn ⇒ Object
Create a new callback of the following type: Compare two items, for sorting typedef int (zhashx_comparator_fn) ( const void *item1, const void *item2);.
- .create_finalizer_for(ptr) ⇒ Proc
-
.deserializer_fn ⇒ Object
Create a new callback of the following type: Deserializes a longstr into an item.
-
.destructor_fn ⇒ Object
Create a new callback of the following type: Destroy an item typedef void (zhashx_destructor_fn) ( void **item);.
-
.duplicator_fn ⇒ Object
Create a new callback of the following type: Duplicate an item typedef void * (zhashx_duplicator_fn) ( const void *item);.
-
.free_fn ⇒ Object
Create a new callback of the following type: Destroy an item.
-
.hash_fn ⇒ Object
Create a new callback of the following type: Hash function for keys.
-
.new ⇒ CZMQ::Zhashx
Create a new, empty hash container.
-
.serializer_fn ⇒ Object
Create a new callback of the following type: Serializes an item to a longstr.
-
.test(verbose) ⇒ void
Self test of this class.
-
.unpack(frame) ⇒ CZMQ::Zhashx
Unpack binary frame into a new hash table.
-
.unpack_own(frame, deserializer) ⇒ CZMQ::Zhashx
Same as unpack but uses a user-defined deserializer function to convert a longstr back into item format.
Instance Method Summary collapse
-
#__ptr ⇒ ::FFI::Pointer
(also: #to_ptr)
Return internal pointer.
-
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
Nullify internal pointer and return pointer pointer.
-
#__undef_finalizer ⇒ void
Undefines the finalizer for this object.
-
#comment(format, *args) ⇒ void
Add a comment to hash table before saving to disk.
-
#cursor ⇒ ::FFI::Pointer
After a successful first/next method, returns the key for the item that was returned.
-
#delete(key) ⇒ void
Remove an item specified by key from the hash table.
-
#destroy ⇒ void
Destroy a hash container and all items in it.
-
#dup ⇒ Zhashx
Make a copy of the list; items are duplicated if you set a duplicator for the list, otherwise not.
-
#dup_v2 ⇒ Zhashx
Make copy of hash table; if supplied table is null, returns null.
-
#first ⇒ ::FFI::Pointer
Simple iterator; returns first item in hash table, in no given order, or NULL if the table is empty.
-
#freefn(key, free_fn) ⇒ ::FFI::Pointer
Set a free function for the specified hash table item.
-
#initialize(ptr, finalize = true) ⇒ Zhashx
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
-
#insert(key, item) ⇒ Integer
Insert item into hash table with specified key and item.
-
#keys ⇒ Zlistx
Return a zlistx_t containing the keys for the items in the table.
-
#load(filename) ⇒ Integer
Load hash table from a text file in name=value format; hash table must already exist.
-
#lookup(key) ⇒ ::FFI::Pointer
Return the item at the specified key, or null.
-
#next ⇒ ::FFI::Pointer
Simple iterator; returns next item in hash table, in no given order, or NULL if the last item was already returned.
- #null? ⇒ Boolean
-
#pack ⇒ Zframe
Serialize hash table to a binary frame that can be sent in a message.
-
#pack_own(serializer) ⇒ Zframe
Same as pack but uses a user-defined serializer function to convert items into longstr.
-
#purge ⇒ void
Delete all items from the hash table.
-
#refresh ⇒ Integer
When a hash table was loaded from a file by zhashx_load, this method will reload the file if it has been modified since, and is “stable”, i.e.
-
#rename(old_key, new_key) ⇒ Integer
Reindexes an item from an old key to a new key.
-
#save(filename) ⇒ Integer
Save hash table to a text file in name=value format.
-
#set_destructor(destructor) ⇒ void
Set a user-defined deallocator for hash items; by default items are not freed when the hash is destroyed.
-
#set_duplicator(duplicator) ⇒ void
Set a user-defined duplicator for hash items; by default items are not copied when the hash is duplicated.
-
#set_key_comparator(comparator) ⇒ void
Set a user-defined comparator for keys; by default keys are compared using strcmp.
-
#set_key_destructor(destructor) ⇒ void
Set a user-defined deallocator for keys; by default keys are freed when the hash is destroyed using free().
-
#set_key_duplicator(duplicator) ⇒ void
Set a user-defined duplicator for keys; by default keys are duplicated using strdup.
-
#set_key_hasher(hasher) ⇒ void
Set a user-defined hash function for keys; by default keys are hashed by a modified Bernstein hashing function.
-
#size ⇒ Integer
Return the number of keys/items in the hash table.
-
#update(key, item) ⇒ void
Update or insert item into hash table with specified key and item.
-
#values ⇒ Zlistx
Return a zlistx_t containing the values for the items in the table.
Constructor Details
#initialize(ptr, finalize = true) ⇒ Zhashx
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
24 25 26 27 28 29 30 31 32 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 24 def initialize(ptr, finalize = true) @ptr = ptr if @ptr.null? @ptr = nil # Remove null pointers so we don't have to test for them. elsif finalize @finalizer = self.class.create_finalizer_for @ptr ObjectSpace.define_finalizer self, @finalizer end end |
Class Method Details
.__new ⇒ Object
18 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 18 alias :__new :new |
.comparator_fn ⇒ Object
WARNING: If your Ruby code doesn’t retain a reference to the FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.
Create a new callback of the following type: Compare two items, for sorting
typedef int (zhashx_comparator_fn) (
const void *item1, const void *item2);
118 119 120 121 122 123 124 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 118 def self.comparator_fn ::FFI::Function.new :int, [:pointer, :pointer], blocking: true do |item1, item2| result = yield item1, item2 result = Integer(result) result end end |
.create_finalizer_for(ptr) ⇒ Proc
35 36 37 38 39 40 41 42 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 35 def self.create_finalizer_for(ptr) ptr_ptr = ::FFI::MemoryPointer.new :pointer Proc.new do ptr_ptr.write_pointer ptr ::CZMQ::FFI.zhashx_destroy ptr_ptr end end |
.deserializer_fn ⇒ Object
WARNING: If your Ruby code doesn’t retain a reference to the FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.
Create a new callback of the following type: Deserializes a longstr into an item. The caller takes ownership of the newly created object.
typedef void * (zhashx_deserializer_fn) (
const char *item_str);
186 187 188 189 190 191 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 186 def self.deserializer_fn ::FFI::Function.new :pointer, [:string], blocking: true do |item_str| result = yield item_str result end end |
.destructor_fn ⇒ Object
WARNING: If your Ruby code doesn’t retain a reference to the FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.
Create a new callback of the following type: Destroy an item
typedef void (zhashx_destructor_fn) (
void **item);
86 87 88 89 90 91 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 86 def self.destructor_fn ::FFI::Function.new :void, [:pointer], blocking: true do |item| result = yield item result end end |
.duplicator_fn ⇒ Object
WARNING: If your Ruby code doesn’t retain a reference to the FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.
Create a new callback of the following type: Duplicate an item
typedef void * (zhashx_duplicator_fn) (
const void *item);
102 103 104 105 106 107 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 102 def self.duplicator_fn ::FFI::Function.new :pointer, [:pointer], blocking: true do |item| result = yield item result end end |
.free_fn ⇒ Object
WARNING: If your Ruby code doesn’t retain a reference to the FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.
Create a new callback of the following type: Destroy an item.
typedef void (zhashx_free_fn) (
void *data);
135 136 137 138 139 140 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 135 def self.free_fn ::FFI::Function.new :void, [:pointer], blocking: true do |data| result = yield data result end end |
.hash_fn ⇒ Object
WARNING: If your Ruby code doesn’t retain a reference to the FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.
Create a new callback of the following type: Hash function for keys.
typedef size_t (zhashx_hash_fn) (
const void *key);
151 152 153 154 155 156 157 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 151 def self.hash_fn ::FFI::Function.new :size_t, [:pointer], blocking: true do |key| result = yield key result = Integer(result) result end end |
.new ⇒ CZMQ::Zhashx
Create a new, empty hash container
195 196 197 198 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 195 def self.new() ptr = ::CZMQ::FFI.zhashx_new() __new ptr end |
.serializer_fn ⇒ Object
WARNING: If your Ruby code doesn’t retain a reference to the FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.
Create a new callback of the following type: Serializes an item to a longstr. The caller takes ownership of the newly created object.
typedef char * (zhashx_serializer_fn) (
const void *item);
169 170 171 172 173 174 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 169 def self.serializer_fn ::FFI::Function.new :pointer, [:pointer], blocking: true do |item| result = yield item result end end |
.test(verbose) ⇒ void
This method returns an undefined value.
Self test of this class.
606 607 608 609 610 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 606 def self.test(verbose) verbose = !(0==verbose||!verbose) # boolean result = ::CZMQ::FFI.zhashx_test(verbose) result end |
.unpack(frame) ⇒ CZMQ::Zhashx
Unpack binary frame into a new hash table. Packed data must follow format defined by zhashx_pack. Hash table is set to autofree. An empty frame unpacks to an empty hash table.
205 206 207 208 209 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 205 def self.unpack(frame) frame = frame.__ptr if frame ptr = ::CZMQ::FFI.zhashx_unpack(frame) __new ptr end |
.unpack_own(frame, deserializer) ⇒ CZMQ::Zhashx
Same as unpack but uses a user-defined deserializer function to convert a longstr back into item format.
216 217 218 219 220 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 216 def self.unpack_own(frame, deserializer) frame = frame.__ptr if frame ptr = ::CZMQ::FFI.zhashx_unpack_own(frame, deserializer) __new ptr end |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
49 50 51 52 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 49 def __ptr raise DestroyedError unless @ptr @ptr end |
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
This detaches the current instance from the native object and thus makes it unusable.
Nullify internal pointer and return pointer pointer.
60 61 62 63 64 65 66 67 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 60 def __ptr_give_ref raise DestroyedError unless @ptr ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer @ptr __undef_finalizer if @finalizer @ptr = nil ptr_ptr end |
#__undef_finalizer ⇒ void
Only use this if you need to and can guarantee that the native object will be freed by other means.
This method returns an undefined value.
Undefines the finalizer for this object.
72 73 74 75 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 72 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#comment(format, *args) ⇒ void
This method returns an undefined value.
Add a comment to hash table before saving to disk. You can add as many comment lines as you like. These comment lines are discarded when loading the file. If you use a null format, all comments are deleted.
410 411 412 413 414 415 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 410 def comment(format, *args) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_comment(self_p, format, *args) result end |
#cursor ⇒ ::FFI::Pointer
After a successful first/next method, returns the key for the item that was returned. This is a constant string that you may not modify or deallocate, and which lasts as long as the item in the hash. After an unsuccessful first/next, returns NULL.
396 397 398 399 400 401 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 396 def cursor() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_cursor(self_p) result end |
#delete(key) ⇒ void
This method returns an undefined value.
Remove an item specified by key from the hash table. If there was no such item, this function does nothing.
267 268 269 270 271 272 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 267 def delete(key) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_delete(self_p, key) result end |
#destroy ⇒ void
This method returns an undefined value.
Destroy a hash container and all items in it
225 226 227 228 229 230 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 225 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zhashx_destroy(self_p) result end |
#dup ⇒ Zhashx
Make a copy of the list; items are duplicated if you set a duplicator for the list, otherwise not. Copying a null reference returns a null reference. Note that this method’s behavior changed slightly for CZMQ v3.x, as it does not set nor respect autofree. It does however let you duplicate any hash table safely. The old behavior is in zhashx_dup_v2.
506 507 508 509 510 511 512 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 506 def dup() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_dup(self_p) result = Zhashx.__new result, true result end |
#dup_v2 ⇒ Zhashx
Make copy of hash table; if supplied table is null, returns null. Does not copy items themselves. Rebuilds new table so may be slow on very large tables. NOTE: only works with item values that are strings since there’s no other way to know how to duplicate the item value.
594 595 596 597 598 599 600 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 594 def dup_v2() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_dup_v2(self_p) result = Zhashx.__new result, false result end |
#first ⇒ ::FFI::Pointer
Simple iterator; returns first item in hash table, in no given order, or NULL if the table is empty. This method is simpler to use than the foreach() method, which is deprecated. To access the key for this item use zhashx_cursor(). NOTE: do NOT modify the table while iterating.
368 369 370 371 372 373 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 368 def first() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_first(self_p) result end |
#freefn(key, free_fn) ⇒ ::FFI::Pointer
Set a free function for the specified hash table item. When the item is destroyed, the free function, if any, is called on that item. Use this when hash items are dynamically allocated, to ensure that you don’t have memory leaks. You can pass ‘free’ or NULL as a free_fn. Returns the item, or NULL if there is no such item.
319 320 321 322 323 324 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 319 def freefn(key, free_fn) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_freefn(self_p, key, free_fn) result end |
#insert(key, item) ⇒ Integer
Insert item into hash table with specified key and item. If key is already present returns -1 and leaves existing item unchanged Returns 0 on success.
239 240 241 242 243 244 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 239 def insert(key, item) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_insert(self_p, key, item) result end |
#keys ⇒ Zlistx
Return a zlistx_t containing the keys for the items in the table. Uses the key_duplicator to duplicate all keys and sets the key_destructor as destructor for the list.
341 342 343 344 345 346 347 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 341 def keys() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_keys(self_p) result = Zlistx.__new result, true result end |
#load(filename) ⇒ Integer
Load hash table from a text file in name=value format; hash table must already exist. Hash values must printable strings; keys may not contain ‘=’ character. Returns 0 if OK, else -1 if a file was not readable.
436 437 438 439 440 441 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 436 def load(filename) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_load(self_p, filename) result end |
#lookup(key) ⇒ ::FFI::Pointer
Return the item at the specified key, or null
290 291 292 293 294 295 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 290 def lookup(key) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_lookup(self_p, key) result end |
#next ⇒ ::FFI::Pointer
Simple iterator; returns next item in hash table, in no given order, or NULL if the last item was already returned. Use this together with zhashx_first() to process all items in a hash table. If you need the items in sorted order, use zhashx_keys() and then zlistx_sort(). To access the key for this item use zhashx_cursor(). NOTE: do NOT modify the table while iterating.
383 384 385 386 387 388 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 383 def next() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_next(self_p) result end |
#null? ⇒ Boolean
44 45 46 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 44 def null? !@ptr or @ptr.null? end |
#pack ⇒ Zframe
Serialize hash table to a binary frame that can be sent in a message. The packed format is compatible with the ‘dictionary’ type defined in rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
; A list of name/value pairs
dictionary = dict-count *( dict-name dict-value )
dict-count = number-4
dict-value = longstr
dict-name = string
; Strings are always length + text contents
longstr = number-4 *VCHAR
string = number-1 *VCHAR
; Numbers are unsigned integers in network byte order
number-1 = 1OCTET
number-4 = 4OCTET
Comments are not included in the packed data. Item values MUST be strings.
478 479 480 481 482 483 484 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 478 def pack() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_pack(self_p) result = Zframe.__new result, true result end |
#pack_own(serializer) ⇒ Zframe
Same as pack but uses a user-defined serializer function to convert items into longstr.
491 492 493 494 495 496 497 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 491 def pack_own(serializer) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_pack_own(self_p, serializer) result = Zframe.__new result, true result end |
#purge ⇒ void
This method returns an undefined value.
Delete all items from the hash table. If the key destructor is set, calls it on every key. If the item destructor is set, calls it on every item.
279 280 281 282 283 284 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 279 def purge() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_purge(self_p) result end |
#refresh ⇒ Integer
When a hash table was loaded from a file by zhashx_load, this method will reload the file if it has been modified since, and is “stable”, i.e. not still changing. Returns 0 if OK, -1 if there was an error reloading the file.
449 450 451 452 453 454 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 449 def refresh() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_refresh(self_p) result end |
#rename(old_key, new_key) ⇒ Integer
Reindexes an item from an old key to a new key. If there was no such item, does nothing. Returns 0 if successful, else -1.
303 304 305 306 307 308 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 303 def rename(old_key, new_key) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_rename(self_p, old_key, new_key) result end |
#save(filename) ⇒ Integer
Save hash table to a text file in name=value format. Hash values must be printable strings; keys may not contain ‘=’ character. Returns 0 if OK, else -1 if a file error occurred.
423 424 425 426 427 428 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 423 def save(filename) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_save(self_p, filename) result end |
#set_destructor(destructor) ⇒ void
This method returns an undefined value.
Set a user-defined deallocator for hash items; by default items are not freed when the hash is destroyed.
519 520 521 522 523 524 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 519 def set_destructor(destructor) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_set_destructor(self_p, destructor) result end |
#set_duplicator(duplicator) ⇒ void
This method returns an undefined value.
Set a user-defined duplicator for hash items; by default items are not copied when the hash is duplicated.
531 532 533 534 535 536 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 531 def set_duplicator(duplicator) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_set_duplicator(self_p, duplicator) result end |
#set_key_comparator(comparator) ⇒ void
This method returns an undefined value.
Set a user-defined comparator for keys; by default keys are compared using strcmp. The callback function should return zero (0) on matching items.
569 570 571 572 573 574 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 569 def set_key_comparator(comparator) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_set_key_comparator(self_p, comparator) result end |
#set_key_destructor(destructor) ⇒ void
This method returns an undefined value.
Set a user-defined deallocator for keys; by default keys are freed when the hash is destroyed using free().
543 544 545 546 547 548 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 543 def set_key_destructor(destructor) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_set_key_destructor(self_p, destructor) result end |
#set_key_duplicator(duplicator) ⇒ void
This method returns an undefined value.
Set a user-defined duplicator for keys; by default keys are duplicated using strdup.
555 556 557 558 559 560 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 555 def set_key_duplicator(duplicator) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_set_key_duplicator(self_p, duplicator) result end |
#set_key_hasher(hasher) ⇒ void
This method returns an undefined value.
Set a user-defined hash function for keys; by default keys are hashed by a modified Bernstein hashing function.
581 582 583 584 585 586 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 581 def set_key_hasher(hasher) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_set_key_hasher(self_p, hasher) result end |
#size ⇒ Integer
Return the number of keys/items in the hash table
329 330 331 332 333 334 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 329 def size() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_size(self_p) result end |
#update(key, item) ⇒ void
This method returns an undefined value.
Update or insert item into hash table with specified key and item. If the key is already present, destroys old item and inserts new one. If you set a container item destructor, this is called on the old value. If the key was not already present, inserts a new item. Sets the hash cursor to the new item.
255 256 257 258 259 260 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 255 def update(key, item) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_update(self_p, key, item) result end |
#values ⇒ Zlistx
Return a zlistx_t containing the values for the items in the table. Uses the duplicator to duplicate all items and sets the destructor as destructor for the list.
354 355 356 357 358 359 360 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhashx.rb', line 354 def values() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhashx_values(self_p) result = Zlistx.__new result, true result end |