jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1163218 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem: MemoryKernelImpl.java NodeImpl.java NodeList.java NodeListLarge.java NodeListOld.java NodeListSmall.java NodeMap.java Revision.java
Date Tue, 30 Aug 2011 14:02:47 GMT
Author: thomasm
Date: Tue Aug 30 14:02:46 2011
New Revision: 1163218

URL: http://svn.apache.org/viewvc?rev=1163218&view=rev
Log:
Trying to support large child node lists (WIP)

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeList.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListLarge.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListOld.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListSmall.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeMap.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java?rev=1163218&r1=1163217&r2=1163218&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
Tue Aug 30 14:02:46 2011
@@ -47,15 +47,17 @@ public class MemoryKernelImpl implements
     private long headRevId;
     private TreeMap<Long, Revision> revisions;
     private ArrayList<Revision> revisionList;
-    private NodeImpl headRoot;
+    private NodeMap nodeMap;
+    private long headRoot;
+    private long revisionRoot;
     private NonDescendingClock clock = new NonDescendingClock(System.currentTimeMillis());
     private final CommitGate gate = new CommitGate();
 
     private MemoryKernelImpl(String name) {
+        nodeMap = new NodeMap();
         if (name.startsWith("fs:")) {
             String dir = name.substring("fs:".length());
-            FileBlobStore s = new FileBlobStore(dir);
-            ds = s;
+            ds = new FileBlobStore(dir);
         } else {
             ds = new MemoryBlobStore();
         }
@@ -73,17 +75,37 @@ public class MemoryKernelImpl implements
 
     public void clear() {
         headRevId = 0;
-        init();
+        headRoot = 0;
+        revisionRoot = 0;
         ds.clear();
+        nodeMap.clear();
+        init();
     }
 
     private void init() {
         revisions = new TreeMap<Long, Revision>();
         revisionList = new ArrayList<Revision>();
-        headRoot = new NodeImpl(headRevId);
+        setRoot(new NodeImpl(nodeMap, headRevId));
+//        setRevisionRoot(new NodeImpl(nodeMap, headRevId));
         commit("+\"/\" {}", "create root node");
     }
 
+    private NodeImpl getRoot() {
+        return nodeMap.getNode(headRoot);
+    }
+
+    private void setRoot(NodeImpl root) {
+        headRoot = nodeMap.addNode(root);
+    }
+
+    private NodeImpl getRevisionRoot() {
+        return nodeMap.getNode(revisionRoot);
+    }
+
+    private void setRevisionRoot(NodeImpl r) {
+        revisionRoot = nodeMap.addNode(r);
+    }
+
     private void commit(String jsonDiff, String msg) {
         Revision r = new Revision(headRevId, clock.time(), headRoot, jsonDiff, msg);
         revisions.put(headRevId, r);
@@ -125,15 +147,15 @@ public class MemoryKernelImpl implements
                 t.read(':');
                 int todoSupportAddProperty;
                 t.read('{');
-                NodeImpl n = NodeImpl.parse(t, headRevId);
-                headRoot = headRoot.cloneAndAddChildNode(PathUtils.concat(fromRoot, path),
false, null, n, headRevId);
+                NodeImpl n = NodeImpl.parse(nodeMap, t, headRevId);
+                setRoot(getRoot().cloneAndAddChildNode(PathUtils.concat(fromRoot, path),
false, null, n, headRevId));
                 n.append(w, -1, 0, -1, false);
                 w.appendWhitespace("\n");
                 break;
             case '-':
                 path = t.readString();
                 w.append("- ").value(PathUtils.concat(rootPath, path));
-                headRoot = headRoot.cloneAndRemoveChildNode(PathUtils.concat(fromRoot, path),
headRevId);
+                setRoot(getRoot().cloneAndRemoveChildNode(PathUtils.concat(fromRoot, path),
headRevId));
                 w.appendWhitespace("\n");
                 break;
             case '^':
@@ -148,14 +170,14 @@ public class MemoryKernelImpl implements
                     value = t.readRawValue().trim();
                     String nodeName = PathUtils.concat(fromRoot, PathUtils.getParentPath(path));
                     String propertyName = PathUtils.getName(path);
-                    if (headRoot.getNode(nodeName).hasProperty(propertyName)) {
+                    if (getRoot().getNode(nodeName).hasProperty(propertyName)) {
                         w.append("^ ").key(PathUtils.concat(rootPath, path));
                     } else {
                         w.append("+ ").key(PathUtils.concat(rootPath, path));
                     }
                     w.append(value);
                 }
-                headRoot = headRoot.cloneAndSetProperty(PathUtils.concat(fromRoot, path),
value, headRevId);
+                setRoot(getRoot().cloneAndSetProperty(PathUtils.concat(fromRoot, path), value,
headRevId));
                 w.appendWhitespace("\n");
                 break;
             case '>':
@@ -225,13 +247,13 @@ public class MemoryKernelImpl implements
                         position = PathUtils.getName(from);
                     }
                 }
-                NodeImpl node = headRoot.getNode(from);
+                NodeImpl node = getRoot().getNode(from);
                 if (!inPlaceRename) {
-                    headRoot = headRoot.cloneAndRemoveChildNode(from, headRevId);
+                    setRoot(getRoot().cloneAndRemoveChildNode(from, headRevId));
                 }
-                headRoot = headRoot.cloneAndAddChildNode(to, before, position, node, headRevId);
+                setRoot(getRoot().cloneAndAddChildNode(to, before, position, node, headRevId));
                 if (inPlaceRename) {
-                    headRoot = headRoot.cloneAndRemoveChildNode(from, headRevId);
+                    setRoot(getRoot().cloneAndRemoveChildNode(from, headRevId));
                 }
                 break;
             default:
@@ -246,7 +268,7 @@ public class MemoryKernelImpl implements
     }
 
     public String getRevisions(long since, int maxEntries) {
-        Revision find = new Revision(0, since, null, null, null);
+        Revision find = new Revision(0, since, 0, null, null);
         int index = Collections.binarySearch(revisionList, find, new Comparator<Revision>()
{
             public int compare(Revision o1, Revision o2) {
                 long t1 = o1.getTime(), t2 = o2.getTime();
@@ -297,7 +319,7 @@ public class MemoryKernelImpl implements
         }
         path = path.substring(1);
         long revId = parseRevisionId(revisionId);
-        NodeImpl root = revisions.get(revId).getRootNode();
+        NodeImpl root = nodeMap.getNode(revisions.get(revId).getRoot());
         NodeImpl n = root.getNode(path);
         if (n == null) {
             throw new RuntimeException("path not found: " + path);
@@ -314,7 +336,7 @@ public class MemoryKernelImpl implements
         }
         path = path.substring(1);
         long revId = parseRevisionId(revisionId);
-        NodeImpl n = revisions.get(revId).getRootNode();
+        NodeImpl n = nodeMap.getNode(revisions.get(revId).getRoot());
         if (n == null) {
             return false;
         }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java?rev=1163218&r1=1163217&r2=1163218&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
Tue Aug 30 14:02:46 2011
@@ -24,7 +24,7 @@ import org.apache.jackrabbit.mk.util.Pat
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.LinkedHashMap;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
 
@@ -34,24 +34,35 @@ import java.util.Map.Entry;
 public class NodeImpl {
 
     private final long revId;
+    private final NodeMap map;
     private HashMap<String, String> properties;
-    private LinkedHashMap<String, NodeImpl> childNodes;
+    private NodeListSmall childNodes;
     private String path;
+    private long id;
 
-    public NodeImpl(long revId) {
+    public NodeImpl(NodeMap map, long revId) {
+        this.map = map;
         this.revId = revId;
     }
 
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
     public NodeImpl clone(long revId) {
         if (revId == this.revId) {
             return this;
         }
-        NodeImpl clone = new NodeImpl(revId);
+        NodeImpl clone = new NodeImpl(map, revId);
         if (properties != null) {
             clone.properties = new HashMap<String, String>(properties);
         }
         if (childNodes != null) {
-            clone.childNodes = new LinkedHashMap<String, NodeImpl>(childNodes);
+            clone.childNodes = new NodeListSmall(childNodes);
         }
         return clone;
     }
@@ -69,7 +80,7 @@ public class NodeImpl {
             return childNodes.containsKey(path);
         }
         String child = path.substring(0, index);
-        NodeImpl n = childNodes.get(child);
+        NodeImpl n = getChildNode(child);
         if (n == null) {
             return false;
         }
@@ -85,16 +96,24 @@ public class NodeImpl {
         }
         int index = PathUtils.getNextSlash(path, 0);
         if (index < 0) {
-            return childNodes.get(path);
+            return getChildNode(path);
         }
         String child = path.substring(0, index);
-        NodeImpl n = childNodes.get(child);
+        NodeImpl n = getChildNode(child);
         if (n == null) {
             return null;
         }
         return n.getNode(path.substring(index + 1));
     }
 
+    private NodeImpl getChildNode(String name) {
+        return map.getNode(childNodes.get(name));
+    }
+
+    private void addChildNode(String name, NodeImpl node) {
+        childNodes.put(name, map.addNode(node));
+    }
+
     public NodeImpl cloneAndAddChildNode(String path, boolean before, String position, NodeImpl
newNode, long revId) {
         int index = PathUtils.getNextSlash(path, 0);
         if (index < 0) {
@@ -103,13 +122,13 @@ public class NodeImpl {
             return clone;
         }
         String child = path.substring(0, index);
-        NodeImpl n = childNodes.get(child);
+        NodeImpl n = getChildNode(child);
         if (n == null) {
             throw new RuntimeException("Node not found: " + path);
         }
         NodeImpl n2 = n.cloneAndAddChildNode(path.substring(index + 1), before, position,
newNode, revId);
         NodeImpl c = clone(revId);
-        c.childNodes.put(child, n2);
+        c.addChildNode(child, n2);
         return c;
     }
 
@@ -121,13 +140,13 @@ public class NodeImpl {
             return clone;
         }
         String child = path.substring(0, index);
-        NodeImpl n = childNodes.get(child);
+        NodeImpl n = getChildNode(child);
         if (n == null) {
             throw new RuntimeException("Node not found: " + path);
         }
         NodeImpl n2 = n.cloneAndRemoveChildNode(path.substring(index + 1), revId);
         NodeImpl c = clone(revId);
-        c.childNodes.put(child, n2);
+        c.addChildNode(child, n2);
         return c;
     }
 
@@ -139,13 +158,13 @@ public class NodeImpl {
             return clone;
         }
         String child = path.substring(0, index);
-        NodeImpl n = childNodes.get(child);
+        NodeImpl n = getChildNode(child);
         if (n == null) {
             throw new RuntimeException("Node not found: " + path);
         }
         NodeImpl n2 = n.cloneAndSetProperty(path.substring(index + 1), value, revId);
         NodeImpl c = clone(revId);
-        c.childNodes.put(child, n2);
+        c.addChildNode(child, n2);
         return c;
     }
 
@@ -163,17 +182,10 @@ public class NodeImpl {
         if (path != null) {
             json.appendWhitespace("/* ").append(path).append(" */");
         }
+        json.appendWhitespace("/* ").append("" + id).append(" */");
         return json.toString();
     }
 
-    public void appendChildNodes(JsopBuilder json, int childOffset, int childCount) {
-        if (childNodes != null) {
-            for (Entry<String, NodeImpl> e : childNodes.entrySet()) {
-                json.value(e.getKey());
-            }
-        }
-    }
-
     public void append(JsopBuilder json, int depth, long offset, int count, boolean childNodeCount)
{
         json.object();
         if (properties != null) {
@@ -190,18 +202,16 @@ public class NodeImpl {
                 json.key(":childNodeCount").value(childNodes.size());
             }
             if (count != 0) {
-                for (Entry<String, NodeImpl> e : childNodes.entrySet()) {
-                    if (offset > 0) {
-                        offset--;
-                        continue;
+                for (Iterator<String> it = childNodes.getNames(offset); it.hasNext()
&& count != 0;) {
+                    if (count > 0) {
+                        count--;
                     }
-                    if (count < 0 || count-- > 0) {
-                        json.key(e.getKey());
-                        if (depth == 0) {
-                            json.object().endObject();
-                        } else {
-                            e.getValue().append(json, depth - 1, 0, -1, childNodeCount);
-                        }
+                    String s = it.next();
+                    json.key(s);
+                    if (depth == 0) {
+                        json.object().endObject();
+                    } else {
+                        getChildNode(s).append(json, depth - 1, 0, -1, childNodeCount);
                     }
                 }
             }
@@ -211,18 +221,19 @@ public class NodeImpl {
 
     void addChildNode(String name, boolean before, String position, NodeImpl node) {
         if (childNodes == null) {
-            childNodes = new LinkedHashMap<String, NodeImpl>();
+            childNodes = new NodeListSmall();
         } else if (childNodes.containsKey(name)) {
             throw new RuntimeException("Node already exists: " + name);
         }
         if (Constants.NODE_NAME_AS_PROPERTY) {
             node.setProperty(":name", JsopBuilder.encode(name));
         }
-        childNodes.put(name, node);
+        addChildNode(name, node);
         if (before || position != null) {
             boolean moveNext = false;
             ArrayList<String> move = new ArrayList<String>();
-            for (String entry : childNodes.keySet()) {
+            for (Iterator<String> it = childNodes.getNames(0); it.hasNext();) {
+                String entry = it.next();
                 if (entry.equals(name)) {
                     // don't move new entry
                 } else if (moveNext) {
@@ -269,12 +280,12 @@ public class NodeImpl {
         }
     }
 
-    public static NodeImpl parse(JsopTokenizer t, long revId) {
-        return parse(t, revId, null);
+    public static NodeImpl parse(NodeMap map, JsopTokenizer t, long revId) {
+        return parse(map, t, revId, null);
     }
 
-    public static NodeImpl parse(JsopTokenizer t, long revId, String path) {
-        NodeImpl node = new NodeImpl(revId);
+    public static NodeImpl parse(NodeMap map, JsopTokenizer t, long revId, String path) {
+        NodeImpl node = new NodeImpl(map, revId);
         if (path != null) {
             node.setPath(path);
         }
@@ -284,7 +295,7 @@ public class NodeImpl {
                 t.read(':');
                 if (t.matches('{')) {
                     String childPath = path == null || key == null ? null : PathUtils.concat(path,
key);
-                    node.addChildNode(key, false, null, parse(t, revId, childPath));
+                    node.addChildNode(key, false, null, parse(map, t, revId, childPath));
                 } else {
                     String value = t.readRawValue().trim();
                     if (!key.equals(":childNodeCount")) {
@@ -305,16 +316,11 @@ public class NodeImpl {
         return path;
     }
 
-    public String[] getChildNodeNames() {
+    public Iterator<String> getChildNodeNames() {
         if (childNodes == null || childNodes.size() == 0) {
-            return new String[0];
-        }
-        String[] names = new String[childNodes.size()];
-        int i = 0;
-        for (String c : childNodes.keySet()) {
-            names[i++] = c;
+            return new ArrayList<String>().iterator();
         }
-        return names;
+        return childNodes.getNames(0);
     }
 
     public Iterable<Entry<String, String>> getProperties() {

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeList.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeList.java?rev=1163218&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeList.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeList.java
Tue Aug 30 14:02:46 2011
@@ -0,0 +1,19 @@
+package org.apache.jackrabbit.mk.mem;
+
+import java.util.Iterator;
+
+interface NodeList {
+
+    long size();
+
+    boolean containsKey(String name);
+
+    Long get(String name);
+
+    void put(String name, Long x);
+
+    Iterator<String> getNames(long offset);
+
+    Long remove(String name);
+
+}

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListLarge.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListLarge.java?rev=1163218&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListLarge.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListLarge.java
Tue Aug 30 14:02:46 2011
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.mem;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Iterator;
+
+public class NodeListLarge implements NodeList {
+
+    private final NodeMap map;
+    private ArrayList<Child> children;
+
+    NodeListLarge(NodeMap map) {
+        this.map = map;
+        children = new ArrayList<Child>();
+    }
+
+    public boolean containsKey(String name) {
+        for (Child c : children) {
+            if (c.possiblyContains(name)) {
+                return load(c).containsKey(name);
+            }
+        }
+        return false;
+    }
+
+    private NodeList load(Child c) {
+        return new NodeListSmall();
+    }
+
+    public Long get(String name) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Iterator<String> getNames(long offset) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void put(String name, Long x) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public Long remove(String name) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public long size() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    static class Child {
+        static final int BLOOM_FILTER_SIZE = 256;
+        BitSet nameBloomFilter = new BitSet(BLOOM_FILTER_SIZE);
+        long size;
+        long id;
+        boolean possiblyContains(String name) {
+            return nameBloomFilter.get(name.hashCode() & (BLOOM_FILTER_SIZE - 1));
+        }
+        void addName(String name) {
+            nameBloomFilter.set(name.hashCode() & (BLOOM_FILTER_SIZE - 1));
+        }
+    }
+
+}

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListOld.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListOld.java?rev=1163218&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListOld.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListOld.java
Tue Aug 30 14:02:46 2011
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.mem;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+import org.apache.jackrabbit.mk.json.JsopBuilder;
+import org.apache.jackrabbit.mk.json.JsopTokenizer;
+
+/**
+ * A node list that can contain any number of child nodes.
+ */
+public class NodeListOld {
+
+    private final NodeMap map;
+    private int size;
+    private boolean isLarge;
+    private LinkedHashMap<String, Long> list;
+
+    public NodeListOld(NodeListOld clone) {
+        this.map = clone.map;
+        this.size = clone.size;
+        this.isLarge = clone.isLarge;
+        this.list = new LinkedHashMap<String, Long>(clone.list);
+    }
+
+    public NodeListOld(NodeMap map) {
+        this.map = map;
+        list = new LinkedHashMap<String, Long>();
+    }
+
+    public long size() {
+        return size;
+    }
+
+    public boolean containsKey(String name) {
+        if (isLarge) {
+            for (Long x : list.values()) {
+                boolean c = getList(x).containsKey(name);
+                if (c) {
+                    return true;
+                }
+            }
+            return false;
+        } else {
+            return list.containsKey(name);
+        }
+    }
+
+    public Long get(String name) {
+        if (isLarge) {
+            for (Long x : list.values()) {
+                Long r = getList(x).get(name);
+                if (r != null) {
+                    return r;
+                }
+            }
+            return null;
+        } else {
+            return list.get(name);
+        }
+    }
+
+    public void put(String name, Long x) {
+        if (!isLarge && size < map.getMaxMemoryChildren()) {
+            Long old = list.put(name, x);
+            if (old != null) {
+                throw new AssertionError("old child " + name + ": " + old + " new: " + x);
+            }
+            size++;
+            return;
+        }
+        if (!isLarge) {
+            convertToLarge();
+        }
+        int todo;
+    }
+
+    private void convertToLarge() {
+        isLarge = true;
+        list = null;
+        int todo;
+    }
+
+    private void convertToSmall() {
+        LinkedHashMap<String, Long> l2 = new LinkedHashMap<String, Long>();
+        isLarge = false;
+        int todo;
+    }
+
+//    public Iterator<String> getNames(long offset) {
+//        if (isLarge) {
+//            for (Long x : list.values()) {
+//                Long r = getList(x).get(name);
+//                if (r != null) {
+//                    return r;
+//                }
+//            }
+//            return null;
+//
+//        } else {
+//            Iterator<String> it = list.keySet().iterator();
+//            while (offset > 0 && it.hasNext()) {
+//                offset--;
+//                it.next();
+//            }
+//            return it;
+//        }
+//    }
+
+    public Long remove(String name) {
+        if (isLarge) {
+            if (size > map.getMaxMemoryChildren() / 2) {
+                convertToSmall();
+            } else {
+
+            }
+        }
+        Long old = list.remove(name);
+        if (old == null) {
+            throw new RuntimeException("Node not found: " + name);
+        }
+        size--;
+        return old;
+    }
+
+    public static NodeListOld fromString(NodeMap map, String s) {
+        NodeListOld x = new NodeListOld(map);
+        JsopTokenizer t = new JsopTokenizer(s);
+        if (t.matches('{')) {
+            if (!t.matches('}')) {
+                do {
+                    String n = t.readString();
+                    t.read(':');
+                    long id = Long.parseLong(t.readString());
+                    x.list.put(n, id);
+                } while (t.matches(','));
+                t.read('}');
+            }
+        } else {
+            t.read('[');
+            x.isLarge = true;
+            if (!t.matches(']')) {
+                int i = 0;
+                do {
+                    long id = Long.parseLong(t.readString());
+                    x.list.put("" + i++, id);
+                } while (t.matches(','));
+                t.read(']');
+            }
+        }
+        return x;
+    }
+
+    public String toString() {
+        JsopBuilder json = new JsopBuilder();
+        if (isLarge) {
+            json.array();
+            for (Long x : list.values()) {
+                json.value(x);
+            }
+            json.endArray();
+        } else {
+            json.object();
+            for (Entry<String, Long> e : list.entrySet()) {
+                json.key(e.getKey()).value(e.getValue());
+            }
+            json.endObject();
+        }
+        return json.toString();
+    }
+
+    private long putList(LinkedHashMap<String, Long> list) {
+        NodeImpl n = new NodeImpl(map, 0);
+        JsopBuilder names = new JsopBuilder();
+        JsopBuilder ids = new JsopBuilder();
+        names.array();
+        ids.array();
+        for (Entry<String, Long> e : list.entrySet()) {
+            String name = e.getKey();
+            names.value(name);
+            ids.value(e.getValue());
+        }
+        names.endArray();
+        ids.endArray();
+        n.setProperty("names", names.toString());
+        n.setProperty("ids", ids.toString());
+        long x = map.addNode(n);
+        return x;
+    }
+
+    private LinkedHashMap<String, Long> getList(long x) {
+        NodeImpl n = map.getNode(x);
+        JsopTokenizer names = new JsopTokenizer(n.getProperty("names"));
+        JsopTokenizer ids = new JsopTokenizer(n.getProperty("ids"));
+        names.read('[');
+        ids.read('[');
+        LinkedHashMap<String, Long> l = new LinkedHashMap<String, Long>();
+        if (!names.matches(']')) {
+            while (true) {
+                l.put(names.readString(), Long.parseLong(ids.readString()));
+                if (!names.matches(',')) {
+                    break;
+                }
+                ids.read(',');
+            }
+            names.read(']');
+            ids.read(']');
+        }
+        return l;
+    }
+
+}

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListSmall.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListSmall.java?rev=1163218&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListSmall.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListSmall.java
Tue Aug 30 14:02:46 2011
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.mem;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+import org.apache.jackrabbit.mk.json.JsopBuilder;
+import org.apache.jackrabbit.mk.json.JsopTokenizer;
+
+public class NodeListSmall implements NodeList {
+
+    private LinkedHashMap<String, Long> list;
+
+    public NodeListSmall(NodeListSmall clone) {
+        this.list = new LinkedHashMap<String, Long>(clone.list);
+    }
+
+    public NodeListSmall() {
+        list = new LinkedHashMap<String, Long>();
+    }
+
+    public long size() {
+        return list.size();
+    }
+
+    public boolean containsKey(String name) {
+        return list.containsKey(name);
+    }
+
+    public Long get(String name) {
+        return list.get(name);
+    }
+
+    public void put(String name, Long x) {
+        list.put(name, x);
+    }
+
+    public Iterator<String> getNames(long offset) {
+        Iterator<String> it = list.keySet().iterator();
+        while (offset > 0 && it.hasNext()) {
+            offset--;
+            it.next();
+        }
+        return it;
+    }
+
+    public Long remove(String name) {
+        Long old = list.remove(name);
+        if (old == null) {
+            throw new RuntimeException("Node not found: " + name);
+        }
+        return old;
+    }
+
+    public static NodeListSmall fromString(String s) {
+        NodeListSmall x = new NodeListSmall();
+        JsopTokenizer t = new JsopTokenizer(s);
+        if (!t.matches('{')) {
+            return null;
+        }
+        if (!t.matches('}')) {
+            do {
+                String n = t.readString();
+                t.read(':');
+                long id = Long.parseLong(t.readString());
+                x.list.put(n, id);
+            } while (t.matches(','));
+            t.read('}');
+        }
+        return x;
+    }
+
+    public String toString() {
+        JsopBuilder json = new JsopBuilder();
+        json.object();
+        for (Entry<String, Long> e : list.entrySet()) {
+            json.key(e.getKey()).value(e.getValue());
+        }
+        json.endObject();
+        return json.toString();
+    }
+
+}

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeMap.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeMap.java?rev=1163218&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeMap.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeMap.java
Tue Aug 30 14:02:46 2011
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.mem;
+
+import java.util.HashMap;
+
+public class NodeMap {
+
+    private HashMap<Long, NodeImpl> nodes = new HashMap<Long, NodeImpl>();
+    private long nextId = 1;
+
+    public long addNode(NodeImpl node) {
+        long x = node.getId();
+        if (!nodes.containsKey(x)) {
+            x = nextId++;
+            node.setId(x);
+            nodes.put(x, node);
+        }
+        return x;
+    }
+
+    public NodeImpl getNode(long x) {
+        return nodes.get(x);
+    }
+
+    public void clear() {
+        nodes.clear();
+        nextId = 1;
+    }
+
+    public int getMaxMemoryChildren() {
+        int todoTestOtherValues;
+        return 20;
+    }
+
+}

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java?rev=1163218&r1=1163217&r2=1163218&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java
Tue Aug 30 14:02:46 2011
@@ -23,11 +23,11 @@ public class Revision {
 
     private final long id;
     private final long time;
-    private final NodeImpl root;
+    private final long root;
     private final String diff;
     private final String msg;
 
-    public Revision(long id, long time, NodeImpl root, String diff, String msg) {
+    public Revision(long id, long time, long root, String diff, String msg) {
         this.id = id;
         this.time = time;
         this.root = root;
@@ -35,7 +35,7 @@ public class Revision {
         this.msg = msg;
     }
 
-    public NodeImpl getRootNode() {
+    public long getRoot() {
         return root;
     }
 



Mime
View raw message