[Zope3-checkins] CVS: Zope3/src/zodb/storage/file - index.py:1.1.2.2

Jeremy Hylton jeremy@zope.com
Fri, 18 Apr 2003 12:28:25 -0400


Update of /cvs-repository/Zope3/src/zodb/storage/file
In directory cvs.zope.org:/tmp/cvs-serv21664

Modified Files:
      Tag: jeremy-new-pack-branch
	index.py 
Log Message:
Use fsBucket instead of fsBTree because we know we only have 256 entries.
Use Q format to struct to pack and unpack numbers.


=== Zope3/src/zodb/storage/file/index.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zodb/storage/file/index.py:1.1.2.1	Wed Apr 16 14:12:32 2003
+++ Zope3/src/zodb/storage/file/index.py	Fri Apr 18 12:28:25 2003
@@ -28,6 +28,9 @@
 # suffix to 6-byte data. This should reduce the overall memory usage to
 # 8-16 bytes per OID.
 #
+# Since the mapping from suffix to data contains at most 256 entries,
+# we use a BTree bucket instead of a full BTree to store the results.
+#
 # We use p64 to convert integers to 8-byte strings and lop off the two
 # high-order bytes when saving. On loading data, we add the leading
 # bytes back before using u64 to convert the data back to (long)
@@ -36,22 +39,15 @@
 from __future__ import generators
 import struct
 
-from zodb.btrees._fsBTree import fsBTree as _fsBTree
+from zodb.btrees._fsBTree import fsBucket
 
 # convert between numbers and six-byte strings
 
-_t32 = 1L<< 32
-
 def num2str(n):
-    h, l = divmod(long(n), _t32)
-    return struct.pack(">HI", h, l)
+    return struct.pack(">Q", n)[2:]
 
 def str2num(s):
-    h, l = struct.unpack(">HI", s)
-    if h:
-        return (long(h) << 32) + l
-    else:
-        return l
+    return struct.unpack(">Q", "\000\000" + s)[0]
 
 class fsIndex:
 
@@ -75,7 +71,7 @@
         treekey = key[:6]
         tree = self._data.get(treekey)
         if tree is None:
-            tree = _fsBTree()
+            tree = fsBucket()
             self._data[treekey] = tree
         tree[key[6:]] = value