# HG changeset patch # User one # Date 1417945412 -32400 # Node ID f98f2704b154765a126251df032bfa31ef1308a4 # Parent c23f70bb791f4fc23524853580dba12b8efd7629 minnerChange diff -r c23f70bb791f -r f98f2704b154 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTransactionManager.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTransactionManager.java Sun Dec 07 15:24:30 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTransactionManager.java Sun Dec 07 18:43:32 2014 +0900 @@ -60,10 +60,14 @@ IndexManager indexManager = new IndexManager(repository.getReservation()); InterfaceTraverser traverser = new InterfaceTraverser(_newRoot, indexManager, true); + long t1 = System.currentTimeMillis(); traverser.createIndex(); - Index nulIndex = traverser.getIndex(); + long t2 = System.currentTimeMillis(); + System.out.println("createIndexTime =" + (t2 - t1)); + + Index index = traverser.getIndex(); ParentIndex nulParentIndex = traverser.getParentIndex(); - DefaultChangeSet newCs = new DefaultChangeSet(_newRoot, cs, list, uuid, _treeName, nextRevision, nulIndex, + DefaultChangeSet newCs = new DefaultChangeSet(_newRoot, cs, list, uuid, _treeName, nextRevision, index, nulParentIndex); DefaultTreeContext newContext = new DefaultTreeContext(_newRoot, newCs); diff -r c23f70bb791f -r f98f2704b154 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Sun Dec 07 15:24:30 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Sun Dec 07 18:43:32 2014 +0900 @@ -2,54 +2,55 @@ import java.nio.ByteBuffer; +import com.sun.corba.se.spi.orbutil.fsm.Guard.Result; + import fj.Ord; import fj.data.List; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; -public class DefaultTreeNode implements TreeNode -{ - //private final DefaultNode wrap; - private List children; - private TreeMap attrs; - private OperationLog log; - - private static final List NIL_LIST = List.nil(); - private static final TreeMap NIL_MAP = TreeMap.empty(Ord.stringOrd); - - public DefaultTreeNode() - { - this(NIL_LIST,NIL_MAP); - } - - public DefaultTreeNode(List _children,TreeMap _attrs) - { - attrs = _attrs; - children = _children; - } +public class DefaultTreeNode implements TreeNode, Comparable { + // private final DefaultNode wrap; + private List children; + private TreeMap attrs; + private OperationLog log; + + private static final List NIL_LIST = List.nil(); + private static final TreeMap NIL_MAP = TreeMap.empty(Ord.stringOrd); + + public DefaultTreeNode() { + this(NIL_LIST, NIL_MAP); + } + + public DefaultTreeNode(List _children, TreeMap _attrs) { + attrs = _attrs; + children = _children; + } - @Override - public DefaultTreeNodeChildren getChildren() - { - return new DefaultTreeNodeChildren(children, attrs); - } + @Override + public DefaultTreeNodeChildren getChildren() { + return new DefaultTreeNodeChildren(children, attrs); + } + + @Override + public DefaultTreeNodeAttribute getAttributes() { + return new DefaultTreeNodeAttribute(children, attrs, log); + } - @Override - public DefaultTreeNodeAttribute getAttributes() - { - return new DefaultTreeNodeAttribute(children, attrs,log); - } - - @Override - public DefaultTreeNode createNewNode(){ - return new DefaultTreeNode(); - } - - public DefaultTreeNode clone() - { - return new DefaultTreeNode(children,attrs); - } + @Override + public DefaultTreeNode createNewNode() { + return new DefaultTreeNode(); + } - + public DefaultTreeNode clone() { + return new DefaultTreeNode(children, attrs); + } + + @Override + public int compareTo(TreeNode o) { + return this.hashCode() - o.hashCode(); + + } + } diff -r c23f70bb791f -r f98f2704b154 src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Sun Dec 07 15:24:30 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Sun Dec 07 18:43:32 2014 +0900 @@ -60,13 +60,13 @@ for (; itNode.hasNext();) { TreeNode targetNode = itNode.next(); if (parentUpdateFlag) - parentIndex = parentIndex.set(targetNode); - List keys = targetNode.getAttributes().getKeys(); - for (String key : keys) { - String value = targetNode.getAttributes().getString(key); - if (value != null) - index = index.set(key, value, targetNode); - } + parentIndex.set(targetNode); +// List keys = targetNode.getAttributes().getKeys(); +// for (String key : keys) { +// String value = targetNode.getAttributes().getString(key); +// if (value != null) +// index = index.set(key, value, targetNode); +// } } } diff -r c23f70bb791f -r f98f2704b154 src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java Sun Dec 07 15:24:30 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java Sun Dec 07 18:43:32 2014 +0900 @@ -127,7 +127,7 @@ } - private TreeMap>> getIndex() { + public TreeMap>> getIndex() { return indexList; } diff -r c23f70bb791f -r f98f2704b154 src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/ParentIndex.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/ParentIndex.java Sun Dec 07 15:24:30 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/ParentIndex.java Sun Dec 07 18:43:32 2014 +0900 @@ -16,15 +16,13 @@ } public ParentIndex(TreeMap parentIndex) { - this.parentIndex = parentIndex; + this.parentIndex = new TreeMap(parentIndex); } public boolean isEmpty(){ return parentIndex.isEmpty(); } - public ParentIndex(ParentIndex parentIndex) { - this.parentIndex = parentIndex.getParentIndex(); - } + public TreeMap getParentIndex() { return parentIndex; diff -r c23f70bb791f -r f98f2704b154 src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/IndexCommitTest.java --- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/IndexCommitTest.java Sun Dec 07 15:24:30 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/IndexCommitTest.java Sun Dec 07 18:43:32 2014 +0900 @@ -38,7 +38,7 @@ JungleTree tree = jungle.getTreeByName("tree"); createTree(tree); tree.getRootNode(); - InterfaceTraverser ifTraverser = tree.getTraverser(); + InterfaceTraverser ifTraverser = tree.getTraverser(true); ifTraverser.find((TreeNode node) -> { ByteBuffer attribute = node.getAttributes().get(key); @@ -57,7 +57,7 @@ ifTraverser.commit(); JungleTree newTree = jungle.getTreeByName("tree"); - InterfaceTraverser newIfTraverser = newTree.getTraverser(); + InterfaceTraverser newIfTraverser = newTree.getTraverser(true); Index newIndex = newIfTraverser.getIndex(); newIndex.get(key,"<-1,0,1>"); JungleTreeEditor editor = tree.getTreeEditor(); diff -r c23f70bb791f -r f98f2704b154 src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/ParentIndexTest.java --- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/ParentIndexTest.java Sun Dec 07 15:24:30 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/ParentIndexTest.java Sun Dec 07 18:43:32 2014 +0900 @@ -7,22 +7,26 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; import junit.framework.Assert; + import org.junit.Test; + import fj.data.Option; public class ParentIndexTest { @Test public void testParentIndex() { - Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTraverser()); + Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTreeEditor (new DefaultTraverser())); jungle.createNewTree("tree"); JungleTree tree = jungle.getTreeByName("tree"); - JungleTreeEditor editor = tree.getIndexTreeEditor(); + JungleTreeEditor editor = tree.getTreeEditor(); DefaultNodePath path = new DefaultNodePath(); editor = editor.addNewChildAt(path, 0).b(); @@ -38,7 +42,7 @@ Iterator children = node.getChildren().iterator(); for (; children.hasNext();) { TreeNode child = children.next(); - TreeNode parent = parentIndex.get(child).some(); + TreeNode parent = parentIndex.get(child); Assert.assertEquals(parent, node); } node = node.getChildren().at(num).b(); @@ -47,11 +51,11 @@ JungleTree oldTree = tree.getOldTree(tree.revision() - 1).b(); TreeNode oldRoot = oldTree.getRootNode(); TreeNode oldNode = oldRoot.getChildren().at(0).b(); - Option oldParentOp = parentIndex.get(oldNode); - Assert.assertTrue(oldParentOp.isNone()); + TreeNode oldParent = parentIndex.get(oldNode); + Assert.assertTrue(oldParent == null); ParentIndex oldTreeParentIndex = oldTree.getParentIndex(); - oldParentOp = oldTreeParentIndex.get(oldNode); - Assert.assertTrue(oldParentOp.isSome()); + oldParent = oldTreeParentIndex.get(oldNode); + Assert.assertTrue(oldParent != null); } }