Advertisement
Guest User

Hash map

a guest
Oct 31st, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. class HashMap:
  2.     keyList = []
  3.     valueList = []
  4.    # if i want to add parameters etc def __init__():
  5.        
  6.     # Returns the index of the key.
  7.     def getIndex(key):
  8.         index = 0;
  9.         for i in HashMap.keyList:
  10.             if (HashMap.keyList[index] == key):
  11.                 return index
  12.             index+=1
  13.         return -1
  14.        
  15.  
  16.  
  17.     # Adds entrys into the lists.
  18.     def addEntry(key,value):
  19.         HashMap.keyList.append(key)
  20.         HashMap.valueList.append(value)
  21.  
  22.  
  23.  
  24.     # Returns a boolean if it has removed the key and the value
  25.     def removeEntry(key):
  26.         index = HashMap.getIndex(key)
  27.         if (index !=-1):
  28.             HashMap.keyList.pop(index)
  29.             HashMap.valueList.pop(index)
  30.             return True
  31.         return False
  32.  
  33.     # Returns the valuelist index of the key
  34.     def getValue(key):
  35.         index = HashMap.getIndex(key)
  36.         if (index !=-1):
  37.             return HashMap.valueList[index]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement