From 76fdb08a8660fc2abe7caecbd2ffca98c9ff06f5 Mon Sep 17 00:00:00 2001 From: Brinx Date: Wed, 16 Jan 2013 22:48:02 +0100 Subject: Fix allow_write --- example.py | 10 +++++----- larch/nodestore.py | 3 ++- larch/nodestore_disk.py | 2 +- larch/nodestore_memory.py | 4 ++-- speed-test | 8 ++++---- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/example.py b/example.py index 53864c9..ecfa42d 100644 --- a/example.py +++ b/example.py @@ -33,11 +33,11 @@ def compute(filename): return md5.hexdigest() -def open_tree(dirname): +def open_tree(dirname, allow_writes=False): key_size = len(compute('/dev/null')) node_size = 4096 - forest = larch.open_forest(key_size=key_size, node_size=node_size, + forest = larch.open_forest(allow_writes=allow_writes, key_size=key_size, node_size=node_size, dirname=dirname) if forest.trees: tree = forest.trees[0] @@ -47,7 +47,7 @@ def open_tree(dirname): def add(filenames): - forest, tree = open_tree('example.tree') + forest, tree = open_tree('example.tree', allow_writes=True) for filename in filenames: checksum = compute(filename) tree.insert(checksum, filename) @@ -64,8 +64,8 @@ def find(checksums): def list_checksums(): forest, tree = open_tree('example.tree') key_size = len(compute('/dev/null')) - minkey = '00' * key_size - maxkey = 'ff' * key_size + minkey = '0' * key_size + maxkey = 'f' * key_size for checksum, filename in tree.lookup_range(minkey, maxkey): print checksum, filename diff --git a/larch/nodestore.py b/larch/nodestore.py index 929450a..dd9b536 100644 --- a/larch/nodestore.py +++ b/larch/nodestore.py @@ -98,7 +98,8 @@ class NodeStore(object): # pragma: no cover ''' - def __init__(self, node_size, codec): + def __init__(self, allow_writes, node_size, codec): + self.allow_writes = allow_writes self.node_size = node_size self.codec = codec self.max_value_size = (node_size / 2) - codec.leaf_header.size diff --git a/larch/nodestore_disk.py b/larch/nodestore_disk.py index 197a411..3cb8ee7 100644 --- a/larch/nodestore_disk.py +++ b/larch/nodestore_disk.py @@ -117,7 +117,7 @@ class NodeStoreDisk(larch.NodeStore): if format is not None: tracing.trace('forcing format_base: %s', format) self.format_base = format - larch.NodeStore.__init__(self, node_size, codec) + larch.NodeStore.__init__(self, allow_writes=allow_writes, node_size=node_size, codec=codec) self.dirname = dirname self.metadata_name = os.path.join(dirname, 'metadata') self.metadata = None diff --git a/larch/nodestore_memory.py b/larch/nodestore_memory.py index 510ce5e..f0598be 100644 --- a/larch/nodestore_memory.py +++ b/larch/nodestore_memory.py @@ -26,8 +26,8 @@ class NodeStoreMemory(larch.NodeStore): ''' - def __init__(self, node_size, codec): - larch.NodeStore.__init__(self, node_size, codec) + def __init__(self,allow_writes, node_size, codec): + larch.NodeStore.__init__(self, allow_writes=allow_writes, node_size=node_size, codec=codec) self.nodes = dict() self.refcounts = dict() self.metadata = dict() diff --git a/speed-test b/speed-test index 5351a82..791fdbc 100755 --- a/speed-test +++ b/speed-test @@ -15,8 +15,8 @@ # along with this program. If not, see . # Excercise my B-tree implementation, for simple benchmarking purposes. -# The benchmark gets a location and an operation count as command line -# arguments. +# The benchmark gets a location and nb of keys to use as command line +# arguments --location=LOCATION and --keys=KEYS. # # If the location is the empty string, an in-memory node store is used. # Otherwise it must be a non-existent directory name. @@ -73,13 +73,13 @@ class SpeedTest(cliapp.Application): raise Exception('You must set number of keys with --keys') if not location: - forest = larch.open_forest(key_size=key_size, node_size=node_size, + forest = larch.open_forest(allow_writes=True, key_size=key_size, node_size=node_size, node_store=larch.NodeStoreMemory) else: if os.path.exists(location): raise Exception('%s exists already' % location) os.mkdir(location) - forest = larch.open_forest(key_size=key_size, node_size=node_size, + forest = larch.open_forest(allow_writes=True, key_size=key_size, node_size=node_size, dirname=location) tree = forest.new_tree() -- cgit v1.2.1