Title: [commits] (vajda) [11245] - enhanced sorted index checking to verify sort order
Revision
11245
Author
vajda
Date
2006-07-23 08:51:18 -0700 (Sun, 23 Jul 2006)

Log Message

- enhanced sorted index checking to verify sort order

Modified Paths

Diff

Modified: trunk/chandler/repository/item/Indexed.py (11244 => 11245)

--- trunk/chandler/repository/item/Indexed.py	2006-07-22 21:47:12 UTC (rev 11244)
+++ trunk/chandler/repository/item/Indexed.py	2006-07-23 15:51:18 UTC (rev 11245)
@@ -629,17 +629,8 @@
                 self._indexes = indexes
 
             for name, index in self._indexes.iteritems():
-                if count != len(index):
-                    logger.error("Lengths of index '%s' (%d) installed on value '%s' (%d) of type %s in attribute %s on %s don't match", name, len(index), self, count, type(self), attribute, item._repr_())
+                if not index._checkIndex(index, logger, name, self,
+                                         item, attribute, count):
                     result = False
-                else:
-                    size = len(index)
-                    for key in index:
-                        size -= 1
-                        if size == 0:
-                            break
-                    if size != 0:
-                        logger.error("Iteration of index '%s' (%d) installed on value '%s' of type %s in attribute %s on %s doesn't match length (%d)", name, len(index) - size, self, type(self), attribute, item._repr_(), len(index))
-                        result = False
                     
         return result

Modified: trunk/chandler/repository/item/Indexes.py (11244 => 11245)

--- trunk/chandler/repository/item/Indexes.py	2006-07-22 21:47:12 UTC (rev 11244)
+++ trunk/chandler/repository/item/Indexes.py	2006-07-23 15:51:18 UTC (rev 11245)
@@ -124,7 +124,35 @@
     def _needsReindexing(self):
         return False
 
+    def _checkIndex(self, _index, logger, name, value, item, attribute, count):
 
+        result = True
+
+        if count != len(self):
+            logger.error("Lengths of index '%s' (%d) installed on value '%s' (%d) of type %s in attribute %s on %s don't match", name, len(self), value, count, type(value), attribute, item._repr_())
+            result = False
+
+        else:
+            size, result = _index._checkIterateIndex(logger, name, value,
+                                                     item, attribute)
+            if size != 0:
+                logger.error("Iteration of index '%s' (%d) installed on value '%s' of type %s in attribute %s on %s doesn't match length (%d)", name, count - size, value, type(value), attribute, item._repr_(), count)
+                result = False
+
+        return result
+
+    def _checkIterateIndex(self, logger, name, value, item, attribute):
+        
+        size = len(self)
+
+        for key in self:
+            size -= 1
+            if size < 0:
+                break
+
+        return size, True
+
+
 class NumericIndex(Index):
     """
     This implementation of a numeric index is not persisted, it is
@@ -516,9 +544,44 @@
         self._subIndexes.remove((uuid, attr, name))
 
     def _needsReindexing(self):
+
         return True
 
+    def _checkIndex(self, _index, logger, name, value, item, attribute, count):
 
+        return self._index._checkIndex(self, logger, name, value,
+                                       item, attribute, count)
+
+    def _checkIterateIndex(self, logger, name, value, item, attribute):
+
+        size = len(self)
+        prevKey = None
+        result = True
+
+        compare = self.compare
+        descending = self._descending
+        if descending:
+            word = 'lesser'
+        else:
+            word = 'greater'
+
+        for key in self:
+            size -= 1
+            if size < 0:
+                break
+            if prevKey is not None:
+                if descending:
+                    sorted = compare(prevKey, key) >= 0
+                else:
+                    sorted = compare(prevKey, key) <= 0
+                if not sorted:
+                    logger.error("Sorted index '%s' installed on value '%s' of type %s in attribute %s on %s is not sorted properly: value for %s is %s than the value for %s", name, value, type(value), attribute, item._repr_(), repr(prevKey), word, repr(key))
+                    result = False
+            prevKey = key
+
+        return size, result
+
+
 class AttributeIndex(SortedIndex):
 
     def __init__(self, valueMap, index, **kwds):




_______________________________________________
Commits mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/commits

Reply via email to