Skip to content

Commit

Permalink
StringMap completed, need to write some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoudimus committed Jun 8, 2010
1 parent c434ad7 commit f4335c7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions stringmap.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -84,8 +84,22 @@ def calculate_coord(self, x, y, dist):
def choose_pivot_strings(self, axis, m=5): def choose_pivot_strings(self, axis, m=5):
"""Chooses two pivot strings on the h-th dimension""" """Chooses two pivot strings on the h-th dimension"""
random_string = random.choice(self.string_list) random_string = random.choice(self.string_list)

random_string_idx = self.string_list.index(random_string)
return 0, 0
# 2 spaces max, would be really nice to use
# a namedtuple for this.
pivots = [random_string_idx, 0]
pivot_dist = [-1000000, -1000000]
for i in xrange(m):
for c in [0, 1]:
furthest_dist_rand = self.get_distance(i, pivots[c], axis)
# if the distance returned is bigger than the maximum
# distance for a coordinate
if furthest_dist_rand > pivot_dist[c]:
pivot_dist[c] = furthest_dist_rand
pivots[c] = i

return *pivots


def get_distance(self, coord_a, coord_b, axis): def get_distance(self, coord_a, coord_b, axis):
"""Get distance of two strings (indexed by coord_a and coord_b) """Get distance of two strings (indexed by coord_a and coord_b)
Expand Down

0 comments on commit f4335c7

Please sign in to comment.