import hashmap_d

states = hashmap_d.new()
hashmap_d.set(states,'Oregon','OR')


cities = hashmap_d.new()
hashmap_d.set(cities,'CA','San Francisco')

print '-' * 20
print "%s"% hashmap_d.get(cities,'CA')

import hashmap
states = hashmap.new()
hashmap.set(states,'CN','china')
hashmap.set(cities,'china','Beijing')

print '-' * 20
print "%s"% hashmap.get(states,'CN')

hashmap.get_slot(cities,'CN','china')
hashmap.list(states)
hashmap.list(cities)

mystuff = {'apple':'I am apples!'}
print mystuff['apple']

def apple():
	print "i am apples!"

apple()
import hashmap

# create a mapping of state to abbreviation
states = hashmap.new()
# get_slot gets invoked every time set is called
hashmap.set(states, 'Oregon', 'OR')
# hashmap.set(states, 'Florida', 'FL')
# hashmap.set(states, 'California', 'CA')
# hashmap.set(states, 'New York', 'NY')
# hashmap.set(states, 'Michigan', 'MI')
print "states[174]: ", states[174]
print "states: ", states, "\n"
# print "hash_key: ", hashmap.hash_key(states, 'Oregon')
# print "get_bucket: ", hashmap.get_bucket(states, 'Oregon')
print "get_slot: ", hashmap.get_slot(states, 'Oregon')

# # create a basic set of states and some cities in them
# cities = hashmap.new()
# hashmap.set(cities, 'CA', 'San Francisco')
# hashmap.set(cities, 'MI', 'Detroit')
# hashmap.set(cities, 'FL', 'Jacksonville')

# # add some more cities
# hashmap.set(cities, 'NY', 'New York')
# hashmap.set(cities, 'OR', 'Portland')


# # print out some cities
# print '-' * 10
# print "NY State has: %s" % hashmap.get(cities, 'NY')
# print "OR State has: %s" % hashmap.get(cities, 'OR')
print "returns hash_key =", hash_key
print '=' *50

print '->' * 5, "def get_bucket(aMap, key)", '<-' * 5
print "getting get_bucket(aMap, key)"
get_bucket = hashmap.get_bucket(aMap, key)
bucket_id = hash_key
aMap[bucket_id]
print "get_bucket = ", get_bucket
print "bucket_id = ", bucket_id
print "returns aMap[bucket_id] =", aMap[bucket_id]
print '=' *50

print '->' * 5, "def get_slot(aMap, key, default=None)",'<-' * 5
print "getting get_slot(aMap, key, default=None)"
get_slot = hashmap.get_slot(aMap, key, value) 
# bucket = get_bucket
bucket = get_bucket
print "bucket = ", bucket
print "returns get_slot = ", get_slot
print '=' *50

print '->' * 5, "def set(aMap, key, default=None)",'<-' * 5
print "getting set(aMap, key, value)"
set1 = hashmap.set(aMap, key, value)
i, k, v = get_slot
print "bucket = ", bucket
print "i, k, v = ", i, k, v
print "aMap contents: ",aMap
print '=' *50
Exemple #4
0
hashmap.set(cities, 'CA', 'San Francisco')
hashmap.set(cities, 'MI', 'Detroit')
hashmap.set(cities, 'FL', 'Jacksonville')

# Add some more cities
hashmap.set(cities, 'NY', 'Some Town')
hashmap.set(cities, 'OR', 'Portland')

# Print out some cities
print '_' * 60
print "Let me play with hash key, print it out for cities:", hashmap.hash_key(cities, 'CA')
print '_' * 60

print "This is 'cities' hashmap object: ", cities
print "This is Bucket", cities[hashmap.hash_key(states, 'CA')]
print "This is we get slot:", hashmap.get_slot(cities, 'MI')
print
print '_' * 40
print "NY State has: %s" % hashmap.get(cities, 'NY')
print "OR State has: %s" % hashmap.get(cities, 'OR')

# Print out some states
print '_' * 40
print "Michigan's abbreviation is: %s" % hashmap.get(states, 'Michigan')
print "Florida's abbreviation is %s" % hashmap.get(states, 'Florida')

# do it by using the state then cities dict
print '_' * 40
print "Michigan has %s" % hashmap.get(cities, hashmap.get(states, 'Michigan'))
print "Florida has %s" % hashmap.get(cities, hashmap.get(states, 'Florida'))
import hashmap

sample = hashmap.new()
print "empty dict: "
print sample

hashmap.set(sample, "key1", "value1")
hashmap.set(sample, "key2", "value2")
hashmap.set(sample, "key3", "value3")
hashmap.set(sample, "apples", "bananas")

print "hash_key: "
print hashmap.hash_key(sample, "key1")
print hashmap.hash_key(sample, "key2")
print hashmap.hash_key(sample, "key3")
print hashmap.hash_key(sample, "apples")

print "get_bucket: "
print hashmap.get_bucket(sample, "key1")

print "get_slot: "
print hashmap.get_slot(sample, "key1")
print hashmap.get_slot(sample, "key2")
print hashmap.get_slot(sample, "key3")

print "dictionary again: "
print sample

print "list: "
print hashmap.list(sample)
Exemple #6
0
import hashmap

if __name__ == "__main__":
    amap = hashmap.new()
    print amap
    num = hashmap.hash_key(amap, 3)
    print num
    value = hashmap.get_bucket(amap, 3)
    print value

    print hashmap.get_slot(amap, 3)