changeset 283:11285c2fbc8b

fix TreeMap delete bag
author tatsuki
date Fri, 30 Dec 2016 05:40:16 +0900
parents 5da8a19dbe76
children 49a5391df988
files src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/CreateTreeMethod.java src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/index/CreateIndexBenchMark.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/Node.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/index/IndexUpdater.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/index/ParentIndex.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/ParentIndexPutTest.java
diffstat 7 files changed, 117 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/CreateTreeMethod.java	Fri Dec 30 05:40:16 2016 +0900
@@ -0,0 +1,46 @@
+package jp.ac.u_ryukyu.ie.cr.benchMark;
+
+import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath;
+import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor;
+import jp.ac.u_ryukyu.ie.cr.jungle.util.Either;
+import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error;
+import junit.framework.Assert;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Created by e115731 on 2016/12/28.
+ */
+public class CreateTreeMethod {
+
+    public static JungleTreeEditor createTree(JungleTreeEditor editor, String key, String indexKey, int _maxHeight, NodePath path) {
+        JungleTreeEditor newEditor = createTree(editor, key, indexKey, 0, _maxHeight, path);
+        Either<Error,JungleTreeEditor> either = newEditor.success();
+        if (either.isA())
+            Assert.fail();
+        return either.b();
+    }
+
+    private static JungleTreeEditor createTree(JungleTreeEditor editor, String key, String indexKey, int _curY, int _maxHeight, NodePath path) {
+        if (_curY == _maxHeight) {
+            return editor;
+        }
+        for (int i = 0; i < 3; i++) {
+            Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, i);
+            if (either.isA())
+                Assert.fail();
+            editor = either.b();
+            String value = path.add(i).toString();
+            either = editor.putAttribute(path.add(i), key, ByteBuffer.wrap(value.getBytes()));
+            if (either.isA())
+                Assert.fail();
+            editor = either.b();
+            either = editor.putAttribute(path.add(i), indexKey, ByteBuffer.wrap(value.getBytes()));
+            if (either.isA())
+                Assert.fail();
+            editor = either.b();
+            editor = createTree(editor, key, indexKey, _curY + 1, _maxHeight, path.add(i));
+        }
+        return editor;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/index/CreateIndexBenchMark.java	Fri Dec 30 05:40:16 2016 +0900
@@ -0,0 +1,54 @@
+package jp.ac.u_ryukyu.ie.cr.benchMark.index;
+
+import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle;
+import jp.ac.u_ryukyu.ie.cr.jungle.Jungle;
+import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath;
+import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath;
+import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor;
+import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser;
+import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree;
+import jp.ac.u_ryukyu.ie.cr.jungle.util.Either;
+import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error;
+import org.junit.Assert;
+
+import java.nio.ByteBuffer;
+
+import static jp.ac.u_ryukyu.ie.cr.benchMark.CreateTreeMethod.createTree;
+
+/**
+ * Created by e115731 on 2016/12/30.
+ */
+public class CreateIndexBenchMark {
+    public static void main(String args[]) {
+        String key = "key";
+        String indexKey = "indexKey";
+        Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTraverser());
+        JungleTree tree = jungle.createNewTree("Tree");
+        JungleTreeEditor editor = tree.getJungleTreeEditor();
+        NodePath path = new DefaultNodePath();
+        System.out.println("start create Tree");
+        createTree(editor, key, indexKey, 3, path);
+        System.out.println("end create Tree");
+        for (int i = 1; i <= 10; i++) {
+            NodePath editNodePath = new DefaultNodePath();
+            //editNodePath = editNodePath.add(0).add(0).add(0).add(0).add(0).add(0).add(0).add(0).add(0);
+            editNodePath = editNodePath.add(0).add(0);
+            Long t1 = System.currentTimeMillis();
+            for (int j = 0; j < (20 * i); j++) {
+                System.out.println(j);
+                editor = tree.getJungleTreeEditor();
+                System.out.println("edit前");
+                Either<Error, JungleTreeEditor> either = editor.putAttribute(editNodePath, "key", ByteBuffer.wrap("value".getBytes()));
+                System.out.println("edit後");
+                Assert.assertFalse(either.isA());
+                editor = either.b();
+                System.out.println("commit前");
+                either = editor.success();
+                System.out.println("commit後");
+                Assert.assertFalse(either.isA());
+            }
+            Long t2 = System.currentTimeMillis();
+            System.out.println("edit count = " + (i * 20) + " : time = " + (t2 - t1));
+        }
+    }
+}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/Node.java	Fri Dec 30 03:55:55 2016 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/Node.java	Fri Dec 30 05:40:16 2016 +0900
@@ -106,7 +106,7 @@
 
             return new rebuildNode<>(false, newParent);
         }
-        return new rebuildNode<>(false,null);
+        return new rebuildNode<>(false,new EmptyNode<>());
     }
 
     @SuppressWarnings("unchecked")
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/index/IndexUpdater.java	Fri Dec 30 03:55:55 2016 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/index/IndexUpdater.java	Fri Dec 30 05:40:16 2016 +0900
@@ -41,11 +41,10 @@
             String value = attribute.getString(key);
             newIndex = newIndex.set(key, value, currentNode);
         }
-        System.out.println("end");
         return new Pair<Index,ParentIndex>(newIndex,newParentIndex);
     }
 
-
+static int count = 0;
     private Pair<Index,ParentIndex> delete(List<TreeNode> editedNodeList, ParentIndex parentIndex, Index newIndex, ParentIndex newParentIndex) {
         for (TreeNode node : editedNodeList) {
             newParentIndex = newParentIndex.deleteAllChildren(node);
@@ -53,13 +52,15 @@
             if (parentOp.isPresent())
                 newIndex = newIndex.delete(node);
             while (parentOp.isPresent()) {
+                count ++;
+                System.out.println(count);
                 TreeNode parent = parentOp.get();
                 ParentIndex tmp = newParentIndex.deleteAllChildren(parent);
                 if (tmp.equals(newParentIndex))
                     break;
                 newParentIndex = tmp;
-                parentOp = parentIndex.get(node);
-                newIndex = newIndex.delete(node);
+                parentOp = parentIndex.get(parent);
+                newIndex = newIndex.delete(parent);
             }
         }
         return new Pair<Index,ParentIndex>(newIndex,newParentIndex);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/index/ParentIndex.java	Fri Dec 30 03:55:55 2016 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/index/ParentIndex.java	Fri Dec 30 05:40:16 2016 +0900
@@ -50,6 +50,7 @@
       TreeMap<TreeNode,TreeNode> tmp  = newParentIndex.delete(child);//削除するノードが無かった場合、同じオブジェクトを返す
       if (tmp.equals(newParentIndex))  //同じオブジェクトだった場合、今のノードとその全ての子ノードはParentIndexに登録されてないから抜ける
         return this;
+      newParentIndex = tmp;
     }
     return new ParentIndex(newParentIndex);
   }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java	Fri Dec 30 03:55:55 2016 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java	Fri Dec 30 05:40:16 2016 +0900
@@ -5,6 +5,8 @@
 import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList;
 import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter;
 import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext;
+import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index;
+import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex;
 import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog;
 import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation;
 import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DefaultTreeContext;
@@ -33,7 +35,7 @@
 
 
     @Override
-    public Either<Error, TransactionManager> commit(TreeNode newRoot, final TreeOperationLog _log,List<TreeNode> editNodeList) {
+    public Either<Error, TransactionManager> commit(TreeNode newRoot, final TreeOperationLog _log, List<TreeNode> editNodeList) {
         long currentRevision = tip.revision();
         long nextRevision = currentRevision + 1;
 
@@ -61,8 +63,11 @@
 
         };
 
-        InterfaceTraverser traverser = new InterfaceTraverser(newRoot, true);
+        Index index = tip.getIndex();
+        ParentIndex parentIndex = tip.getParentIndex();
+        InterfaceTraverser traverser = new InterfaceTraverser(newRoot, index, parentIndex, true);
         traverser.updateIndex(editNodeList);
+        //traverser.createIndex();
         TreeContext newTreeContext = new DefaultTreeContext(newRoot, tip, list, uuid, _treeName, nextRevision, traverser);
 
         if (repository.compareAndSet(newTreeContext.prev(), newTreeContext)) {
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/ParentIndexPutTest.java	Fri Dec 30 03:55:55 2016 +0900
+++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/ParentIndexPutTest.java	Fri Dec 30 05:40:16 2016 +0900
@@ -38,7 +38,7 @@
         JungleTree tree = jungle.getTreeByName("tree");
         JungleTreeEditor editor = tree.getJungleTreeEditor();
         NodePath path = new DefaultNodePath();
-        createTree(editor,key,indexKey,4,path);
+        createTree(editor,key,indexKey,2,path);
         TreeNode oldTreeRoot = tree.getRootNode();
         ParentIndex parentIndex = tree.getParentIndex();
         JungleNodeIterator iterator = new JungleNodeIterator(oldTreeRoot);
@@ -53,12 +53,12 @@
         }
 
         JungleTreeEditor editor2 = tree.getJungleTreeEditor();
-        path = path.add(0).add(0).add(2);
+        path = path.add(0).add(0);//.add(2);
         Either<Error, JungleTreeEditor> either = editor2.putAttribute(path,addAttributeKey, ByteBuffer.wrap("value".getBytes()) );
         Assert.assertFalse(either.isA());
         JungleTreeEditor editor3 = either.b();
         NodePath path2 = new DefaultNodePath();
-        path2 = path2.add(1).add(1).add(2);
+        path2 = path2.add(1).add(1);//.add(2);
         Either<Error, JungleTreeEditor> either2 = editor3.putAttribute(path2,addAttributeKey, ByteBuffer.wrap("value".getBytes()) );
         Assert.assertFalse(either2.isA());
         JungleTreeEditor editor4 = either2.b();