Пример #1
0
 def test_search(self):
     L = UnorderedList()
     data = [randint(0, 100) for i in range(10)]
     for d in data:
         L.add(d)
     self.assertTrue(all([L.search(i) for i in data]))
     self.assertFalse(all([L.search(i) for i in range(100, 110)]))
	def put(self,key,value):
		hash_value = self.hash_function(key,len(self.slot))
		if self.slot[hash_value] == None: # if slot is empty and no list is created yet!
			l = UnorderedList() # Create a list then add the key:value pair
			self.slot[hash_value] = l
			l.add(key,value)
		else:
			l = self.slot[hash_value] # if list is already present for hash value 
			if l.search(key):
				i = l.index(key)
				l.getNode(i).set_value(value) #replace
			else:
				l.add(key,value)