Class: Expanse::Set
Class Method Summary collapse
Instance Method Summary collapse
- #add(key) ⇒ Object (also: #<<)
- #clear ⇒ Object
- #count_range(lo, hi) ⇒ Object
- #delete(key) ⇒ Object (also: #remove)
- #each ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
- #include?(key) ⇒ Boolean (also: #key?, #member?)
-
#initialize ⇒ Set
constructor
A new instance of Set.
- #last ⇒ Object
-
#mem_used ⇒ Object
Bytes of native trie memory currently held by this set (arena accounting from
expanse_set_mem_used; excludes the Ruby wrapper object itself). - #next(key) ⇒ Object
- #prev(key) ⇒ Object
- #rank(key) ⇒ Object
- #select(k) ⇒ Object
- #size ⇒ Object (also: #length, #count)
Constructor Details
Class Method Details
.finalize(ptr) ⇒ Object
113 114 115 |
# File 'lib/expanse.rb', line 113 def self.finalize(ptr) proc { Native.expanse_set_free(ptr) if ptr && !ptr.null? } end |
Instance Method Details
#add(key) ⇒ Object Also known as: <<
117 118 119 |
# File 'lib/expanse.rb', line 117 def add(key) Native.expanse_set_insert(@ptr, key) != 0 end |
#clear ⇒ Object
149 150 151 152 |
# File 'lib/expanse.rb', line 149 def clear Native.expanse_set_clear(@ptr) self end |
#count_range(lo, hi) ⇒ Object
193 194 195 |
# File 'lib/expanse.rb', line 193 def count_range(lo, hi) Native.expanse_set_count_range(@ptr, lo, hi) end |
#delete(key) ⇒ Object Also known as: remove
122 123 124 |
# File 'lib/expanse.rb', line 122 def delete(key) Native.expanse_set_remove(@ptr, key) != 0 end |
#each ⇒ Object
197 198 199 200 201 202 203 204 |
# File 'lib/expanse.rb', line 197 def each return enum_for(:each) unless block_given? cur = first while cur yield cur cur = self.next(cur) end end |
#empty? ⇒ Boolean
139 140 141 |
# File 'lib/expanse.rb', line 139 def empty? size.zero? end |
#first ⇒ Object
154 155 156 157 158 159 |
# File 'lib/expanse.rb', line 154 def first buf = Fiddle::Pointer.malloc(8) if Native.expanse_set_first(@ptr, buf) != 0 buf.to_str(8).unpack1("Q<") end end |
#include?(key) ⇒ Boolean Also known as: key?, member?
127 128 129 |
# File 'lib/expanse.rb', line 127 def include?(key) Native.expanse_set_contains(@ptr, key) != 0 end |
#last ⇒ Object
161 162 163 164 165 166 |
# File 'lib/expanse.rb', line 161 def last buf = Fiddle::Pointer.malloc(8) if Native.expanse_set_last(@ptr, buf) != 0 buf.to_str(8).unpack1("Q<") end end |
#mem_used ⇒ Object
Bytes of native trie memory currently held by this set (arena accounting
from expanse_set_mem_used; excludes the Ruby wrapper object itself).
145 146 147 |
# File 'lib/expanse.rb', line 145 def mem_used Native.expanse_set_mem_used(@ptr) end |
#next(key) ⇒ Object
168 169 170 171 172 173 |
# File 'lib/expanse.rb', line 168 def next(key) buf = Fiddle::Pointer.malloc(8) if Native.expanse_set_next_after(@ptr, key, buf) != 0 buf.to_str(8).unpack1("Q<") end end |
#prev(key) ⇒ Object
175 176 177 178 179 180 |
# File 'lib/expanse.rb', line 175 def prev(key) buf = Fiddle::Pointer.malloc(8) if Native.expanse_set_prev_before(@ptr, key, buf) != 0 buf.to_str(8).unpack1("Q<") end end |
#rank(key) ⇒ Object
182 183 184 |
# File 'lib/expanse.rb', line 182 def rank(key) Native.expanse_set_count_below(@ptr, key) end |
#select(k) ⇒ Object
186 187 188 189 190 191 |
# File 'lib/expanse.rb', line 186 def select(k) buf = Fiddle::Pointer.malloc(8) if Native.expanse_set_by_count(@ptr, k, buf) != 0 buf.to_str(8).unpack1("Q<") end end |
#size ⇒ Object Also known as: length, count
133 134 135 |
# File 'lib/expanse.rb', line 133 def size Native.expanse_set_len(@ptr) end |