Class: Expanse::Map
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object (also: #get)
- #[]=(key, val) ⇒ Object (also: #set)
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #each ⇒ Object
- #first ⇒ Object
-
#initialize ⇒ Map
constructor
A new instance of Map.
- #key?(key) ⇒ Boolean (also: #include?)
-
#mem_used ⇒ Object
Bytes of native trie memory currently held by this map (arena accounting from
expanse_map_mem_used; excludes the Ruby wrapper object itself). - #next(key) ⇒ Object
- #size ⇒ Object (also: #length)
Constructor Details
Class Method Details
.finalize(ptr) ⇒ Object
215 216 217 |
# File 'lib/expanse.rb', line 215 def self.finalize(ptr) proc { Native.expanse_map_free(ptr) if ptr && !ptr.null? } end |
Instance Method Details
#[](key) ⇒ Object Also known as: get
225 226 227 228 229 230 |
# File 'lib/expanse.rb', line 225 def [](key) buf = Fiddle::Pointer.malloc(8) if Native.expanse_map_get(@ptr, key, buf) != 0 buf.to_str(8).unpack1("Q<") end end |
#[]=(key, val) ⇒ Object Also known as: set
219 220 221 222 |
# File 'lib/expanse.rb', line 219 def []=(key, val) Native.expanse_map_insert(@ptr, key, val, nil) val end |
#clear ⇒ Object
256 257 258 259 |
# File 'lib/expanse.rb', line 256 def clear Native.expanse_map_clear(@ptr) self end |
#delete(key) ⇒ Object
233 234 235 236 237 238 |
# File 'lib/expanse.rb', line 233 def delete(key) buf = Fiddle::Pointer.malloc(8) if Native.expanse_map_remove(@ptr, key, buf) != 0 buf.to_str(8).unpack1("Q<") end end |
#each ⇒ Object
277 278 279 280 281 282 283 284 |
# File 'lib/expanse.rb', line 277 def each return enum_for(:each) unless block_given? pair = first while pair yield pair[0], pair[1] pair = self.next(pair[0]) end end |
#first ⇒ Object
261 262 263 264 265 266 267 |
# File 'lib/expanse.rb', line 261 def first k_buf = Fiddle::Pointer.malloc(8) v_buf = Fiddle::Pointer.malloc(8) if Native.expanse_map_first(@ptr, k_buf, v_buf) != 0 [k_buf.to_str(8).unpack1("Q<"), v_buf.to_str(8).unpack1("Q<")] end end |
#key?(key) ⇒ Boolean Also known as: include?
240 241 242 |
# File 'lib/expanse.rb', line 240 def key?(key) !self[key].nil? end |
#mem_used ⇒ Object
Bytes of native trie memory currently held by this map (arena accounting
from expanse_map_mem_used; excludes the Ruby wrapper object itself).
252 253 254 |
# File 'lib/expanse.rb', line 252 def mem_used Native.expanse_map_mem_used(@ptr) end |
#next(key) ⇒ Object
269 270 271 272 273 274 275 |
# File 'lib/expanse.rb', line 269 def next(key) k_buf = Fiddle::Pointer.malloc(8) v_buf = Fiddle::Pointer.malloc(8) if Native.expanse_map_next_after(@ptr, key, k_buf, v_buf) != 0 [k_buf.to_str(8).unpack1("Q<"), v_buf.to_str(8).unpack1("Q<")] end end |
#size ⇒ Object Also known as: length
245 246 247 |
# File 'lib/expanse.rb', line 245 def size Native.expanse_map_len(@ptr) end |