Commits

Mikhail Korobov committed 1fed2ba

make root() constant

Comments (0)

Files changed (2)

 
         This may be useful e.g. for handling single-character umlauts.
         """
-        return self._similar_keys("", key, self.dct.root(), replaces)
+        return self._similar_keys("", key, self.dct.ROOT, replaces)
 
     @classmethod
     def compile_replaces(cls, replaces):
         Returns a list with keys of this DAWG that are prefixes of the ``key``.
         '''
         res = []
-        index = self.dct.root()
+        index = self.dct.ROOT
         if not isinstance(key, bytes):
             key = key.encode('utf8')
 
         b_prefix = prefix.encode('utf8')
         res = []
 
-        index = self.dct.follow_bytes(b_prefix, self.dct.root())
+        index = self.dct.follow_bytes(b_prefix, self.dct.ROOT)
         if index is None:
             return res
 
 
     def iterkeys(self, prefix=""):
         b_prefix = prefix.encode('utf8')
-        index = self.dct.follow_bytes(b_prefix, self.dct.root())
+        index = self.dct.follow_bytes(b_prefix, self.dct.ROOT)
         if index is None:
             return
 
         return self.b_get_value(key) or default
 
     def _follow_key(self, b_key):
-        index = self.dct.follow_bytes(b_key, self.dct.root())
+        index = self.dct.follow_bytes(b_key, self.dct.ROOT)
         if not index:
             return False
 
             prefix = prefix.encode('utf8')
         res = []
 
-        index = self.dct.root()
+        index = self.dct.ROOT
 
         if prefix:
             index = self.dct.follow_bytes(prefix, index)
         if not isinstance(prefix, bytes):
             prefix = prefix.encode('utf8')
 
-        index = self.dct.root()
+        index = self.dct.ROOT
 
         if prefix:
             index = self.dct.follow_bytes(prefix, index)
             prefix = prefix.encode('utf8')
         res = []
 
-        index = self.dct.root()
+        index = self.dct.ROOT
         if prefix:
             index = self.dct.follow_bytes(prefix, index)
             if not index:
         if not isinstance(prefix, bytes):
             prefix = prefix.encode('utf8')
 
-        index = self.dct.root()
+        index = self.dct.ROOT
         if prefix:
             index = self.dct.follow_bytes(prefix, index)
             if not index:
         that maps single-char unicode sitrings to another single-char
         unicode strings.
         """
-        return self._similar_items("", key, self.dct.root(), replaces)
+        return self._similar_items("", key, self.dct.ROOT, replaces)
 
 
     def _similar_item_values(self, start_pos, key, index, replace_chars):
         that maps single-char unicode sitrings to another single-char
         unicode strings.
         """
-        return self._similar_item_values(0, key, self.dct.root(), replaces)
+        return self._similar_item_values(0, key, self.dct.ROOT, replaces)
 
 
 class RecordDAWG(BytesDAWG):

dawg_python/wrapper.py

     def __init__(self):
         self._units = array.array(str("I"))
 
-    def root(self):
-        "Root index"
-        return 0
+    ROOT = 0
+    "Root index"
 
     def has_value(self, index):
         "Checks if a given index is related to the end of a key."
 
     def contains(self, key):
         "Exact matching."
-        index = self.follow_bytes(key, self.root())
+        index = self.follow_bytes(key, self.ROOT)
         if index is None:
             return False
         return self.has_value(index)
 
     def find(self, key):
         "Exact matching (returns value)"
-        index = self.follow_bytes(key, self.root())
+        index = self.follow_bytes(key, self.ROOT)
         if index is None:
             return -1
         if not self.has_value(index):
 
 class Guide(object):
 
+    ROOT = 0
+
     def __init__(self):
         self._units = None
 
-    def root(self):
-        return 0
-
     def child(self, index):
         return self._units[index*2]
 
 
         if self._guide.size():
             self._index_stack = [index]
-            self._last_index = self._dic.root()
+            self._last_index = self._dic.ROOT
         else:
             self._index_stack = []
 
 
         index = self._index_stack[-1]
 
-        if self._last_index != self._dic.root():
+        if self._last_index != self._dic.ROOT:
 
             child_label = self._guide.child(index) # UCharType