Permalink
Browse files

StringMap completed, need to write some tests

  • Loading branch information...
mahmoudimus committed Jun 8, 2010
1 parent c434ad7 commit f4335c7c704236c1b428539dfddc841d4d08fac0
Showing with 16 additions and 2 deletions.
  1. +16 −2 stringmap.py
View
@@ -84,8 +84,22 @@ def calculate_coord(self, x, y, dist):
def choose_pivot_strings(self, axis, m=5):
"""Chooses two pivot strings on the h-th dimension"""
random_string = random.choice(self.string_list)
-
- return 0, 0
+ random_string_idx = self.string_list.index(random_string)
+
+ # 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):
"""Get distance of two strings (indexed by coord_a and coord_b)

0 comments on commit f4335c7

Please sign in to comment.