Class: Hyperactive::Hash::Head
- Inherits:
-
Record::Bass
- Object
- Record::Bass
- Hyperactive::Hash::Head
- Includes:
- Archipelago::Current::ThreadedCollection, Cleaner::Accessors
- Defined in:
- lib/hyperactive/hash.rb
Overview
A class suitable for storing large and often-changing datasets in an Archipelago environment.
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Return the value for
key
. -
#[]=(key, value) ⇒ Object
Insert
value
underkey
in this Hash. -
#clear! ⇒ Object
Remove all key/value pairs from this Hash.
-
#delete(key) ⇒ Object
Delete
key
from this Hash. -
#destroy! ⇒ Object
Clear everything from this Tree and destroy it.
-
#each(&block) ⇒ Object
Will yield to
block
once for each key/value pair in this Hash. -
#empty? ⇒ Boolean
Return whether this Hash is empty.
-
#include?(key) ⇒ Boolean
Returns whether
key
is included in this Hash. -
#initialize ⇒ Head
constructor
Initialize a Hash::Head.
-
#size ⇒ Object
Return the size of this Hash.
Methods included from Cleaner::Accessors
append_features, #dirty?, #is_clean!, #is_dirty!
Methods included from Transactions::Accessors
Methods included from Index::Indexable
Methods included from Record::Persistent
#<=>, append_features, #create, #with_transaction
Constructor Details
#initialize ⇒ Head
Initialize a Hash::Head.
NB: Remember to call create on the new instance or use Head.get_instance to get that done automatically.
71 72 73 74 |
# File 'lib/hyperactive/hash.rb', line 71 def initialize super self.list = nil end |
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
64 65 66 |
# File 'lib/hyperactive/hash.rb', line 64 def list @list end |
Instance Method Details
#[](key) ⇒ Object
Return the value for key
.
93 94 95 96 97 98 99 100 |
# File 'lib/hyperactive/hash.rb', line 93 def [](key) element = Archipelago::Pirate::BLACKBEARD[my_key_for(key), @transaction] if element return element.value else return nil end end |
#[]=(key, value) ⇒ Object
Insert value
under key
in this Hash.
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/hyperactive/hash.rb', line 112 def []=(key, value) self.list ||= Hyperactive::List::Head.get_instance_with_transaction(@transaction) if (element = Archipelago::Pirate::BLACKBEARD[my_key_for(key), @transaction]) element.value = value else element = Element.get_instance_with_transaction(@transaction, key, value, nil) self.list << element element.list_element = self.list.last_element Archipelago::Pirate::BLACKBEARD[my_key_for(key), @transaction] = element end end |
#clear! ⇒ Object
Remove all key/value pairs from this Hash.
157 158 159 160 161 162 163 164 |
# File 'lib/hyperactive/hash.rb', line 157 def clear! self.list = Hyperactive::List::Head.get_instance_with_transaction(@transaction) unless self.list self.list.t_each do |element| element.destroy! end self.list.clear! end |
#delete(key) ⇒ Object
Delete key
from this Hash.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/hyperactive/hash.rb', line 128 def delete(key) self.list ||= Hyperactive::List::Head.get_instance_with_transaction(@transaction) return_value = nil element = Archipelago::Pirate::BLACKBEARD[my_key_for(key), @transaction] if element Archipelago::Pirate::BLACKBEARD.delete(my_key_for(key), @transaction) self.list.unlink!(element.list_element) return_value = element.value element.destroy! end return return_value end |
#destroy! ⇒ Object
Clear everything from this Tree and destroy it.
169 170 171 172 |
# File 'lib/hyperactive/hash.rb', line 169 def destroy! self.clear! super end |
#each(&block) ⇒ Object
Will yield to block
once for each key/value pair in this Hash.
146 147 148 149 150 151 152 |
# File 'lib/hyperactive/hash.rb', line 146 def each(&block) self.list = Hyperactive::List::Head.get_instance_with_transaction(@transaction) unless self.list self.list.each do |element| yield([element.key, element.value]) end end |
#empty? ⇒ Boolean
Return whether this Hash is empty.
86 87 88 |
# File 'lib/hyperactive/hash.rb', line 86 def empty? self.list.empty? end |
#include?(key) ⇒ Boolean
Returns whether key
is included in this Hash.
105 106 107 |
# File 'lib/hyperactive/hash.rb', line 105 def include?(key) Archipelago::Pirate::BLACKBEARD.include?(my_key_for(key), @transaction) end |
#size ⇒ Object
Return the size of this Hash.
79 80 81 |
# File 'lib/hyperactive/hash.rb', line 79 def size self.list.size end |