Rev 3920: Rename EquivalenceTable to LinesDeltaIndex. in http://bzr.arbash-meinel.com/branches/bzr/brisbane/vilajam

John Arbash Meinel john at arbash-meinel.com
Fri Mar 27 20:27:21 GMT 2009


At http://bzr.arbash-meinel.com/branches/bzr/brisbane/vilajam

------------------------------------------------------------
revno: 3920
revision-id: john at arbash-meinel.com-20090327202705-61equbv1i49kphh7
parent: john at arbash-meinel.com-20090327201944-7uorvlyn16yhakvk
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: vilajam
timestamp: Fri 2009-03-27 15:27:05 -0500
message:
  Rename EquivalenceTable to LinesDeltaIndex.
  This helps clarify that it is approximately the same object,
  only it works on lines rather than bytes.
-------------- next part --------------
=== modified file 'bzrlib/_groupcompress_py.py'
--- a/bzrlib/_groupcompress_py.py	2009-03-27 20:12:12 +0000
+++ b/bzrlib/_groupcompress_py.py	2009-03-27 20:27:05 +0000
@@ -23,27 +23,23 @@
 from bzrlib import osutils
 
 
-class EquivalenceTable(object):
-    """This class tracks equivalencies between lists of hashable objects.
+class LinesDeltaIndex(object):
+    """This class indexes matches between strings.
 
     :ivar lines: The 'static' lines that will be preserved between runs.
-    :ival _matching_lines: A dict of {line:[matching offsets]}
+    :ivar _matching_lines: A dict of {line:[matching offsets]}
+    :ivar line_offsets: The byte offset for the end of each line, used to
+        quickly map between a matching line number and the byte location
+    :ivar endpoint: The total number of bytes in self.line_offsets
     """
 
     def __init__(self, lines):
-        self.lines = lines
+        self.lines = []
         self.line_offsets = []
-        self.endpoint = sum(map(len, lines))
+        self.endpoint = 0
+        self._matching_lines = {}
+        self.extend_lines(lines, [True]*len(lines))
         self._right_lines = None
-        # For each line in 'left' give the offset to the other lines which
-        # match it.
-        self._generate_matching_lines()
-
-    def _generate_matching_lines(self):
-        matches = {}
-        for idx, line in enumerate(self.lines):
-            matches.setdefault(line, []).append(idx)
-        self._matching_lines = matches
 
     def _update_matching_lines(self, new_lines, index):
         matches = self._matching_lines
@@ -338,9 +334,7 @@
         raise TypeError('source is not a str')
     if type(target_bytes) is not str:
         raise TypeError('target is not a str')
-    line_locations = EquivalenceTable([])
-    source_lines = osutils.split_lines(source_bytes)
-    line_locations.extend_lines(source_lines, [True]*len(source_lines))
+    line_locations = LinesDeltaIndex(osutils.split_lines(source_bytes))
     delta, _ = line_locations.make_delta(osutils.split_lines(target_bytes),
                                          bytes_length=len(target_bytes))
     return ''.join(delta)

=== modified file 'bzrlib/groupcompress.py'
--- a/bzrlib/groupcompress.py	2009-03-27 20:12:12 +0000
+++ b/bzrlib/groupcompress.py	2009-03-27 20:27:05 +0000
@@ -748,7 +748,7 @@
         :param delta: If False, do not compress records.
         """
         super(PythonGroupCompressor, self).__init__()
-        self.line_locations = EquivalenceTable([])
+        self.line_locations = LinesDeltaIndex([])
         self.lines = self.line_locations.lines
         self._present_prefixes = set()
 
@@ -1784,7 +1784,7 @@
     encode_base128_int,
     decode_base128_int,
     encode_copy_instruction,
-    EquivalenceTable,
+    LinesDeltaIndex,
     )
 try:
     from bzrlib._groupcompress_pyx import (



More information about the bazaar-commits mailing list