MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / _set_value

Method _set_value

data_structures/hashing/hash_table.py:133–176  ·  view source on GitHub ↗

_set_value functions allows to update value at a particular hash Examples: 1. _set_value in HashTable of size 5 >>> ht = HashTable(5) >>> ht.insert_data(10) >>> ht.insert_data(20) >>> ht.insert_data(30) >>> ht._set_value(0,15)

(self, key, data)

Source from the content-addressed store, hash-verified

131 i += 1
132
133 def _set_value(self, key, data):
134 """
135 _set_value functions allows to update value at a particular hash
136
137 Examples:
138 1. _set_value in HashTable of size 5
139 >>> ht = HashTable(5)
140 >>> ht.insert_data(10)
141 >>> ht.insert_data(20)
142 >>> ht.insert_data(30)
143 >>> ht._set_value(0,15)
144 >>> ht.keys()
145 {0: 15, 1: 20, 2: 30}
146
147 2. _set_value in HashTable of size 2
148 >>> ht = HashTable(2)
149 >>> ht.insert_data(17)
150 >>> ht.insert_data(18)
151 >>> ht.insert_data(99)
152 >>> ht._set_value(3,15)
153 >>> ht.keys()
154 {3: 15, 2: 17, 4: 99}
155
156 3. _set_value in HashTable when hash is not present
157 >>> ht = HashTable(2)
158 >>> ht.insert_data(17)
159 >>> ht.insert_data(18)
160 >>> ht.insert_data(99)
161 >>> ht._set_value(0,15)
162 >>> ht.keys()
163 {3: 18, 2: 17, 4: 99, 0: 15}
164
165 4. _set_value in HashTable when multiple hash are not present
166 >>> ht = HashTable(2)
167 >>> ht.insert_data(17)
168 >>> ht.insert_data(18)
169 >>> ht.insert_data(99)
170 >>> ht._set_value(0,15)
171 >>> ht._set_value(1,20)
172 >>> ht.keys()
173 {3: 18, 2: 17, 4: 99, 0: 15, 1: 20}
174 """
175 self.values[key] = data
176 self._keys[key] = data
177
178 @abstractmethod
179 def _collision_resolution(self, key, data=None):

Callers 1

insert_dataMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected