Class: Hyperactive::Hash::Head
- Inherits:
-
Record::Bass
- Object
- Record::Bass
- Hyperactive::Hash::Head
- Includes:
- Archipelago::Current::ThreadedCollection
- Defined in:
- lib/hyperactive/hash.rb
Overview
A class suitable for storing large and often-changing datasets in an Archipelago environment.
Constant Summary
Constants inherited from Record::Bass
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
Attributes inherited from Record::Bass
Attributes included from Transactions::Participant
Instance Method Summary collapse
-
#[](key) ⇒ Object
Return the value for
key. -
#[]=(key, value) ⇒ Object
Insert
valueunderkeyin this Hash. -
#clear! ⇒ Object
Remove all key/value pairs from this Hash.
-
#delete(key) ⇒ Object
Delete
keyfrom this Hash. -
#destroy! ⇒ Object
Clear everything from this Tree and destroy it.
-
#each(&block) ⇒ Object
Will yield to
blockonce for each key/value pair in this Hash. -
#empty? ⇒ Boolean
Return whether this Hash is empty.
-
#include?(key) ⇒ Boolean
Returns whether
keyis included in this Hash. -
#initialize ⇒ Head
constructor
Initialize a Hash::Head.
-
#size ⇒ Object
Return the size of this Hash.
Methods inherited from Record::Bass
#<=>, #create, find, get_instance
Methods included from Hyperactive::Hooker::Pimp
append_features, #load_hook, #save_hook
Methods included from Transactions::Participant
append_features, #with_transaction
Methods included from Transactions::Accessors
Methods included from Index::Indexable
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.
64 65 66 67 |
# File 'lib/hyperactive/hash.rb', line 64 def initialize super self.list = nil end |
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
55 56 57 |
# File 'lib/hyperactive/hash.rb', line 55 def list @list end |
Instance Method Details
#[](key) ⇒ Object
Return the value for key.
86 87 88 89 90 91 92 93 |
# File 'lib/hyperactive/hash.rb', line 86 def [](key) element = Hyperactive::CAPTAIN[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.
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/hyperactive/hash.rb', line 105 def []=(key, value) self.list = Hyperactive::List::Head.get_instance_with_transaction(@transaction) unless self.list if (element = Hyperactive::CAPTAIN[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 Hyperactive::CAPTAIN[my_key_for(key), @transaction] = element end end |
#clear! ⇒ Object
Remove all key/value pairs from this Hash.
150 151 152 153 154 155 156 157 |
# File 'lib/hyperactive/hash.rb', line 150 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.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/hyperactive/hash.rb', line 121 def delete(key) self.list = Hyperactive::List::Head.get_instance_with_transaction(@transaction) unless self.list return_value = nil element = Hyperactive::CAPTAIN[my_key_for(key), @transaction] if element Hyperactive::CAPTAIN.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.
162 163 164 165 |
# File 'lib/hyperactive/hash.rb', line 162 def destroy! self.clear! super end |
#each(&block) ⇒ Object
Will yield to block once for each key/value pair in this Hash.
139 140 141 142 143 144 145 |
# File 'lib/hyperactive/hash.rb', line 139 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.
79 80 81 |
# File 'lib/hyperactive/hash.rb', line 79 def empty? self.list.empty? end |
#include?(key) ⇒ Boolean
Returns whether key is included in this Hash.
98 99 100 |
# File 'lib/hyperactive/hash.rb', line 98 def include?(key) Hyperactive::CAPTAIN.include?(my_key_for(key), @transaction) end |
#size ⇒ Object
Return the size of this Hash.
72 73 74 |
# File 'lib/hyperactive/hash.rb', line 72 def size self.list.size end |