Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 151:d9fbddf77bf6
add class Index
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Sat Nov 22 14:46:44 2014 +0900 @@ -3,9 +3,7 @@ import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; -import fj.Ord; import fj.data.List; -import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Journal; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.NullJournal; @@ -14,7 +12,6 @@ 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.IndexTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultChangeSet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeContext; @@ -23,6 +20,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.Traverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; public class DefaultJungle implements Jungle @@ -84,7 +82,7 @@ }; DefaultTreeNode root = new DefaultTreeNode(); - TreeMap<String, TreeMap<String, List<TreeNode>>> index = TreeMap.empty(Ord.stringOrd); + Index index = new Index(); ParentIndex parentIndex = new ParentIndex(); ChangeSet set = new DefaultChangeSet(root,null,list,uuid,name,0,index,parentIndex); DefaultTreeContext tc = new DefaultTreeContext(root,set);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java Sat Nov 22 14:46:44 2014 +0900 @@ -1,7 +1,5 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; -import fj.data.List; -import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; @@ -19,6 +17,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.GetOldTreeError; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.IndexManager; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; @@ -28,8 +27,9 @@ private final ChangeListWriter writer; private final TreeEditor treeEditor; private final IndexTreeEditor indexTreeEditor; - - public DefaultJungleTree(TreeContext tc, String uuid, ChangeListWriter writer, TreeEditor editor, IndexTreeEditor indexTreeEditor) { + + public DefaultJungleTree(TreeContext tc, String uuid, ChangeListWriter writer, TreeEditor editor, + IndexTreeEditor indexTreeEditor) { this.repository = new AtomicReservableReference<TreeContext>(tc); this.uuid = uuid; this.writer = writer; @@ -42,9 +42,9 @@ TreeContext tc = repository.get(); DefaultTransactionManager txManager = new DefaultTransactionManager(writer, tc, repository, uuid); TreeNode root = tc.getTreeNode(); - TreeMap<String, TreeMap<String, List<TreeNode>>>index = getIndex(); + Index index = getIndex(); ParentIndex parentIndex = getParentIndex(); - return new DefaultJungleTreeEditor(root, txManager, treeEditor, index,parentIndex); + return new DefaultJungleTreeEditor(root, txManager, treeEditor, index, parentIndex); } @Override @@ -52,9 +52,9 @@ TreeContext tc = repository.get(); DefaultTransactionManager txManager = new DefaultTransactionManager(writer, tc, repository, uuid); TreeNode root = tc.getTreeNode(); - TreeMap<String, TreeMap<String, List<TreeNode>>> index = getIndex(); + Index index = getIndex(); ParentIndex parentIndex = getParentIndex(); - return new IndexJungleTreeEditor(root,root, txManager, indexTreeEditor, index, parentIndex); + return new IndexJungleTreeEditor(root, root, txManager, indexTreeEditor, index, parentIndex); } @Override @@ -80,14 +80,14 @@ public InterfaceTraverser getTraverser() { AtomicReservableReference<TreeContext>.Reservation reservation = repository.getReservation(); IndexManager indexManager = new IndexManager(reservation); - TreeMap<String, TreeMap<String, List<TreeNode>>> index = getIndex(); + Index index = getIndex(); if (index != null) return new InterfaceTraverser(getRootNode(), index, indexManager); return new InterfaceTraverser(getRootNode(), indexManager); } @Override - public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { + public Index getIndex() { TreeContext tc = repository.get(); ChangeSet cs = tc.getChangeSet(); return cs.getIndex(); @@ -111,20 +111,19 @@ public Either<Error, JungleTree> getOldTree(long revision) { TreeContext tc = repository.get(); ChangeSet cs = tc.getChangeSet(); - - for (;cs.revision() != revision;) { + + for (; cs.revision() != revision;) { cs = cs.prev(); if (cs == null) return DefaultEither.newA(GetOldTreeError.OLD_TREE_NOT_FOUND); } - + TreeNode root = cs.getRoot(); - + TreeContext oldTc = new DefaultTreeContext(root, cs); String oldTreeUuid = uuid + revision; - JungleTree oldTree = new DefaultJungleTree(oldTc,oldTreeUuid,writer,treeEditor,indexTreeEditor); + JungleTree oldTree = new DefaultJungleTree(oldTc, oldTreeUuid, writer, treeEditor, indexTreeEditor); return DefaultEither.newB(oldTree); } - }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Sat Nov 22 14:46:44 2014 +0900 @@ -1,14 +1,14 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; -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.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; public interface JungleTree @@ -17,7 +17,7 @@ public InterfaceTraverser getTraverser(); public JungleTreeEditor getLocalTreeEditor(); public TreeNode getRootNode(); - public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex(); + public Index getIndex(); public ParentIndex getParentIndex(); public IndexJungleTreeEditor getIndexTreeEditor(); public Iterable<TreeOperation> getLog();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/ChangeSet.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/ChangeSet.java Sat Nov 22 14:46:44 2014 +0900 @@ -1,11 +1,11 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store; -import fj.data.List; -import fj.data.TreeMap; + import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; public interface ChangeSet @@ -18,7 +18,7 @@ public String getTreeName(); public long revision(); - public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex(); + public Index getIndex(); public Iterable<TreeOperation> getOperations(); public ParentIndex getParentIndex(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/IndexTreeEditor.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/IndexTreeEditor.java Sat Nov 22 14:46:44 2014 +0900 @@ -4,7 +4,6 @@ import fj.data.List; -import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultChangeSet.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultChangeSet.java Sat Nov 22 14:46:44 2014 +0900 @@ -1,11 +1,10 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; -import fj.data.List; -import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; public class DefaultChangeSet implements ChangeSet @@ -16,10 +15,10 @@ private final String uuid; private final String treeName; private final long revision; - private final TreeMap<String, TreeMap<String, List<TreeNode>>> index; + private final Index index; private final ParentIndex parentIndex; - public DefaultChangeSet(TreeNode _node,ChangeSet _prev,ChangeList _log,String _uuid, String _treeName, long _revision, TreeMap<String, TreeMap<String, List<TreeNode>>> index,ParentIndex parentIndex) + public DefaultChangeSet(TreeNode _node,ChangeSet _prev,ChangeList _log,String _uuid, String _treeName, long _revision, Index index,ParentIndex parentIndex) { this.root = _node; this.previous = _prev; @@ -75,7 +74,7 @@ } @Override - public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { + public Index getIndex() { return index; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java Sat Nov 22 14:46:44 2014 +0900 @@ -2,8 +2,7 @@ import java.nio.ByteBuffer; -import fj.data.List; -import fj.data.TreeMap; + import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; @@ -24,6 +23,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; public class DefaultJungleTreeEditor implements JungleTreeEditor @@ -32,7 +32,7 @@ private final TreeNode root; private final TreeEditor editor; private final TreeOperationLog log; - private final TreeMap<String, TreeMap<String, List<TreeNode>>> index; + private final Index index; private final ParentIndex parentIndex; // public DefaultJungleTreeEditor(TreeNode root) @@ -40,14 +40,14 @@ // this(root,txManager,_editor,new DefaultTreeOperationLog()); // } - public DefaultJungleTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor, TreeMap<String, TreeMap<String, List<TreeNode>>> index,ParentIndex parentIndex) + public DefaultJungleTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor, Index index,ParentIndex parentIndex) { this(_root,_txManager,_editor,new DefaultTreeOperationLog(),index,parentIndex); } - public DefaultJungleTreeEditor(TreeNode newNode,TransactionManager _txManager,TreeEditor _editor,TreeOperationLog _log, TreeMap<String, TreeMap<String, List<TreeNode>>> index,ParentIndex parentIndex) + public DefaultJungleTreeEditor(TreeNode newNode,TransactionManager _txManager,TreeEditor _editor,TreeOperationLog _log, Index index,ParentIndex parentIndex) { this.root = newNode; this.txManager = _txManager;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTransactionManager.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTransactionManager.java Sat Nov 22 14:46:44 2014 +0900 @@ -2,8 +2,6 @@ import java.util.Iterator; -import fj.data.List; -import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Result; @@ -16,6 +14,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultError; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; public class DefaultTransactionManager implements TransactionManager @@ -35,7 +34,7 @@ } @Override - public Either<Error,TransactionManager> commit(TreeNode _newRoot,final TreeOperationLog _log, TreeMap<String, TreeMap<String, List<TreeNode>>> index,ParentIndex parentIndex) + public Either<Error,TransactionManager> commit(TreeNode _newRoot,final TreeOperationLog _log, Index index,ParentIndex parentIndex) { ChangeSet cs = tip.getChangeSet(); long currentRevision = cs.revision();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java Sat Nov 22 14:46:44 2014 +0900 @@ -4,13 +4,11 @@ import java.util.Iterator; import fj.P2; -import fj.data.List; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.IndexTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; @@ -31,6 +29,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.TreeMapOrd; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.DefaultIndexEditor; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.DeleteChildIndexEditor; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.IndexEditor; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; @@ -41,28 +40,26 @@ private final IndexTreeEditor editor; private final TreeOperationLog log; private final TreeOperationLog tmpLog; - private TreeMap<String, TreeMap<String, List<TreeNode>>> index; + private Index index; private ParentIndex parentIndex; - public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { + public Index getIndex() { return index; } public IndexJungleTreeEditor(TreeNode _root, TreeNode oldRoot, TransactionManager _txManager, - IndexTreeEditor treeEditor, TreeMap<String, TreeMap<String, List<TreeNode>>> index, - ParentIndex parentIndex) { - this(_root, oldRoot, _txManager, treeEditor, new DefaultTreeOperationLog(), new DefaultTreeOperationLog(), index, parentIndex); + IndexTreeEditor treeEditor, Index index, ParentIndex parentIndex) { + this(_root, oldRoot, _txManager, treeEditor, new DefaultTreeOperationLog(), new DefaultTreeOperationLog(), index, + parentIndex); } public IndexJungleTreeEditor(TreeNode _root, TreeNode oldRoot, TransactionManager _txManager, - IndexTreeEditor treeEditor, TreeOperationLog log, TreeMap<String, TreeMap<String, List<TreeNode>>> index, - ParentIndex parentIndex) { + IndexTreeEditor treeEditor, TreeOperationLog log, Index index, ParentIndex parentIndex) { this(_root, oldRoot, _txManager, treeEditor, log, new DefaultTreeOperationLog(), index, parentIndex); } public IndexJungleTreeEditor(TreeNode newNode, TreeNode oldRoot, TransactionManager _txManager, - IndexTreeEditor _editor, TreeOperationLog _log, TreeOperationLog tmpLog, - TreeMap<String, TreeMap<String, List<TreeNode>>> index, ParentIndex parentIndex) { + IndexTreeEditor _editor, TreeOperationLog _log, TreeOperationLog tmpLog, Index index, ParentIndex parentIndex) { this.root = newNode; this.oldRoot = oldRoot; this.txManager = _txManager; @@ -147,9 +144,11 @@ @Override public Either<Error, JungleTreeEditor> success() { - ParentIndex newParentIndex = editParentIndex(tmpLog); + Pair<ParentIndex, Index> newIndexPair = editIndex(tmpLog); + ParentIndex newParentIndex = newIndexPair.left(); + Index newIndex = newIndexPair.right(); TreeOperationLog newLog = log.append(tmpLog); - Either<Error, TransactionManager> either = txManager.commit(root, newLog, index, newParentIndex); + Either<Error, TransactionManager> either = txManager.commit(root, newLog, newIndex, newParentIndex); if (either.isA()) { return DefaultEither.newA(either.a()); } @@ -160,9 +159,10 @@ return DefaultEither.newB(newTreeEditor); } - private ParentIndex editParentIndex(TreeOperationLog tmpLog) { + private Pair<ParentIndex, Index> editIndex(TreeOperationLog tmpLog) { TreeMap<TreeNode, TreeNode> putParentNodeMap = TreeMap.empty(TreeMapOrd.treeNodeOrd); TreeMap<TreeNode, TreeNode> deleteParentNodeMap = TreeMap.empty(TreeMapOrd.treeNodeOrd); + for (TreeOperation log : tmpLog) { NodePath targetNodePath = log.getNodePath(); @@ -171,49 +171,51 @@ System.out.println(log.getNodePath().toString()); } - ParentIndex newParentIndex = parentIndex; + Pair<ParentIndex, Index> indexPair = new Pair<ParentIndex, Index>(parentIndex, index); if (!deleteParentNodeMap.isEmpty()) - newParentIndex = deleteParentIndex(putParentNodeMap, newParentIndex); + indexPair = deleteIndexAttribute(putParentNodeMap, indexPair); - if (!putParentNodeMap.isEmpty()) - newParentIndex = putParentIndex(putParentNodeMap,newParentIndex); + indexPair = putIndexAttribute(putParentNodeMap, indexPair); - return newParentIndex; + ParentIndex newParentIndex = indexPair.left(); + Index newIndex = indexPair.right(); + Pair<ParentIndex, Index> newIndexPair = new Pair<ParentIndex, Index>(newParentIndex, newIndex); + return newIndexPair; } - private ParentIndex deleteParentIndex(TreeMap<TreeNode, TreeNode> deleteParentNodeMap, ParentIndex editParentIndex) { + private Pair<ParentIndex, Index> deleteIndexAttribute(TreeMap<TreeNode, TreeNode> deleteParentNodeMap, + Pair<ParentIndex, Index> indexPair) { + Iterator<P2<TreeNode, TreeNode>> parentNodeIterator = deleteParentNodeMap.iterator(); - ParentIndex newParentIndex = editParentIndex; + ParentIndex newParentIndex = indexPair.left(); + Index newIndex = indexPair.right(); for (; parentNodeIterator.hasNext();) { TreeNode parentNode = parentNodeIterator.next()._1(); - TreeNodeChildren children = parentNode.getChildren(); - Iterator<TreeNode> childrenIterator = children.iterator(); - - for (; childrenIterator.hasNext();) { - TreeNode child = childrenIterator.next(); - newParentIndex = newParentIndex.delete(child); - } + newIndex = newIndex.deleteNodeAll(parentNode); + newParentIndex = newParentIndex.deleteAllChildren(parentNode); } - return newParentIndex; + + Pair<ParentIndex, Index> newIndexPair = new Pair<ParentIndex, Index>(newParentIndex, newIndex); + return newIndexPair; } - private ParentIndex putParentIndex(TreeMap<TreeNode, TreeNode> putParentNodeMap,ParentIndex editParentIndex) { + private Pair<ParentIndex, Index> putIndexAttribute(TreeMap<TreeNode, TreeNode> putParentNodeMap, + Pair<ParentIndex, Index> indexPair) { Iterator<P2<TreeNode, TreeNode>> parentNodeIterator = putParentNodeMap.iterator(); - ParentIndex newParentIndex = editParentIndex; + ParentIndex newParentIndex = indexPair.left(); + Index newIndex = indexPair.right(); for (; parentNodeIterator.hasNext();) { + TreeNode parentNode = parentNodeIterator.next()._1(); - TreeNodeChildren children = parentNode.getChildren(); - Iterator<TreeNode> childrenIterator = children.iterator(); - - for (; childrenIterator.hasNext();) { - TreeNode child = childrenIterator.next(); - newParentIndex = newParentIndex.set(child, parentNode); - } + newIndex = newIndex.putNodeAll(parentNode); + newParentIndex = newParentIndex.addAllChildren(parentNode); + } - return newParentIndex; + Pair<ParentIndex, Index> newIndexPair = new Pair<ParentIndex, Index>(newParentIndex, newIndex); + return newIndexPair; } private TreeMap<TreeNode, TreeNode> getTargetNode(TreeMap<TreeNode, TreeNode> treeNodeMap, TreeNode node,
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/TransactionManager.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/TransactionManager.java Sat Nov 22 14:46:44 2014 +0900 @@ -1,16 +1,16 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; -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.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.ParentIndex; public interface TransactionManager { - public Either<Error,TransactionManager> commit(TreeNode _newRoot,TreeOperationLog _log, TreeMap<String, TreeMap<String, List<TreeNode>>> index,ParentIndex parentIndex); + public Either<Error,TransactionManager> commit(TreeNode _newRoot,TreeOperationLog _log, Index index,ParentIndex parentIndex); public String getUUID(); public long getRevision(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Sat Nov 22 14:46:44 2014 +0900 @@ -14,22 +14,23 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIterator; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.Query; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.IndexManager; public class InterfaceTraverser { // InterfaceTraverser traverser; TreeNode node; - TreeMap<String, TreeMap<String, List<TreeNode>>> index; + Index index; IndexManager indexManager; public InterfaceTraverser(TreeNode _root, IndexManager indexManager) { this.node = _root; - this.index = TreeMap.empty(Ord.stringOrd); + this.index = new Index(); this.indexManager = indexManager; } - public InterfaceTraverser(TreeNode _root, TreeMap<String, TreeMap<String, List<TreeNode>>> index, + public InterfaceTraverser(TreeNode _root, Index index, IndexManager indexManager) { this.node = _root; this.index = index; @@ -40,11 +41,11 @@ indexManager.commit(index); } - public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { + public Index getIndex() { return index; } - public void setIndex(TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { + public void setIndex(Index index) { this.index = index; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/DefaultIndexEditor.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/DefaultIndexEditor.java Sat Nov 22 14:46:44 2014 +0900 @@ -9,19 +9,19 @@ public class DefaultIndexEditor implements IndexEditor { - TreeMap<String, TreeMap<String, List<TreeNode>>> indexTreeMap; + Index index; - public DefaultIndexEditor(TreeMap<String, TreeMap<String, List<TreeNode>>> indexTreeMap) { - this.indexTreeMap = indexTreeMap; + public DefaultIndexEditor(Index index) { + this.index = index; } @Override public IndexEditor delete(TreeNode node) { TreeNodeAttributes attribute = node.getAttributes(); List<String> keys = attribute.getKeys(); - TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexTreeMap = indexTreeMap; + Index newIndexTreeMap = index; for (String key : keys) { - Option<TreeMap<String, List<TreeNode>>> indexOp = indexTreeMap.get(key); + Option<TreeMap<String, List<TreeNode>>> indexOp = index.get(key); if (indexOp.isSome()) { TreeMap<String, List<TreeNode>> index = indexOp.some(); String value = attribute.getString(key); @@ -48,9 +48,9 @@ public IndexEditor add(TreeNode node) { TreeNodeAttributes attribute = node.getAttributes(); List<String> keys = attribute.getKeys(); - TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexTreeMap = indexTreeMap; + TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexTreeMap = index; for (String key : keys) { - Option<TreeMap<String, List<TreeNode>>> indexOp = indexTreeMap.get(key); + Option<TreeMap<String, List<TreeNode>>> indexOp = index.get(key); if (indexOp.isSome()) { TreeMap<String, List<TreeNode>> index = indexOp.some(); String value = attribute.getString(key); @@ -83,7 +83,7 @@ @Override public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { - return indexTreeMap; + return index; } @Override
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/DeleteChildIndexEditor.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/DeleteChildIndexEditor.java Sat Nov 22 14:46:44 2014 +0900 @@ -13,11 +13,11 @@ public class DeleteChildIndexEditor implements IndexEditor { - TreeMap<String, TreeMap<String, List<TreeNode>>> indexTreeMap; + Index index; int pos; - public DeleteChildIndexEditor(int pos, TreeMap<String, TreeMap<String, List<TreeNode>>> indexTreeMap) { - this.indexTreeMap = indexTreeMap; + public DeleteChildIndexEditor(int pos, Index index) { + this.index = index; this.pos = pos; } @@ -25,9 +25,9 @@ public IndexEditor delete(TreeNode node) { TreeNodeAttributes attribute = node.getAttributes(); List<String> keys = attribute.getKeys(); - TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexTreeMap = indexTreeMap; + TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexTreeMap = index; for (String key : keys) { - Option<TreeMap<String, List<TreeNode>>> indexOp = indexTreeMap.get(key); + Option<TreeMap<String, List<TreeNode>>> indexOp = index.get(key); if (indexOp.isSome()) { TreeMap<String, List<TreeNode>> index = indexOp.some(); String value = attribute.getString(key); @@ -54,9 +54,9 @@ public IndexEditor add(TreeNode node) { TreeNodeAttributes attribute = node.getAttributes(); List<String> keys = attribute.getKeys(); - TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexTreeMap = indexTreeMap; + TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexTreeMap = index; for (String key : keys) { - Option<TreeMap<String, List<TreeNode>>> indexOp = indexTreeMap.get(key); + Option<TreeMap<String, List<TreeNode>>> indexOp = index.get(key); if (indexOp.isSome()) { TreeMap<String, List<TreeNode>> index = indexOp.some(); String value = attribute.getString(key); @@ -89,13 +89,13 @@ @Override public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { - return indexTreeMap; + return index; } @Override public IndexEditor edit(TreeNode node) { PathNodeIterator nodeSearcher = new PathNodeIterator(new Pair<TreeNode, NodePath>(node, new DefaultNodePath())); - TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexTreeMap = indexTreeMap; + TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexTreeMap = index; for (; nodeSearcher.hasNext();) { TreeNode deleteNode = nodeSearcher.next().left();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java Sat Nov 22 14:46:44 2014 +0900 @@ -0,0 +1,156 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; + +import java.util.Iterator; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import fj.Ord; +import fj.P2; +import fj.data.List; +import fj.data.Option; +import fj.data.TreeMap; + +public class Index { + + TreeMap<String, TreeMap<String, List<TreeNode>>> indexList; + + public Index() { + this.indexList = TreeMap.empty(Ord.stringOrd); + } + + public Index(TreeMap<String, TreeMap<String, List<TreeNode>>> indexList) { + this.indexList = indexList; + } + + public Index(Index indexList) { + this.indexList = indexList.getIndex(); + } + + public Index set(String key, String value, TreeNode node) { + Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); + if (indexOp.isNone()) + return this; + + TreeMap<String, List<TreeNode>> index = indexOp.some(); + Option<List<TreeNode>> nodeListOp = index.get(value); + + List<TreeNode> newNodeList; + if (nodeListOp.isSome()) { + List<TreeNode> nodeList = nodeListOp.some(); + newNodeList = nodeList.cons(node); + } else { + List<TreeNode> nodeList = List.nil(); + newNodeList = nodeList.cons(node); + } + TreeMap<String, List<TreeNode>> newIndex = index.set(value, newNodeList); + TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexList = indexList.set(key, newIndex); + return new Index(newIndexList); + } + + public Index delete(String key, String value, TreeNode node) { + Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); + if (indexOp.isNone()) + return this; + + TreeMap<String, List<TreeNode>> index = indexOp.some(); + TreeMap<String, List<TreeNode>> newIndex = index; + Option<List<TreeNode>> nodeListOp = index.get(value); + if (nodeListOp.isSome()) { + List<TreeNode> nodeList = nodeListOp.some(); + List<TreeNode> newNodeList = List.nil(); + for (TreeNode indexingNode : nodeList) { + if (indexingNode.equals(node)) + newNodeList = newNodeList.cons(indexingNode); + } + + newIndex = index.set(value, newNodeList); + } else { + return this; + } + TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexList = indexList.set(key, newIndex); + return new Index(newIndexList); + } + + public Index deleteNodeAll(TreeNode node) { + List<String> keys = node.getAttributes().getKeys(); + TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexList = indexList; + + for (String key : keys) { + Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); + if (indexOp.isNone()) + continue; + + TreeMap<String, List<TreeNode>> index = indexOp.some(); + Iterator<P2<String, List<TreeNode>>> indexIterator = index.iterator(); + + TreeMap<String, List<TreeNode>> newIndex = index; + for (; indexIterator.hasNext();) { + List<TreeNode> newNodeList = List.nil(); + P2<String, List<TreeNode>> NodeListP2 = indexIterator.next(); + String value = NodeListP2._1(); + List<TreeNode> targetNodeList = NodeListP2._2(); + for (TreeNode targetNode : targetNodeList) { + if (!node.equals(targetNode)) + newNodeList = newNodeList.cons(targetNode); + } + newIndex = newIndex.set(value, newNodeList); + } + newIndexList = indexList.set(key, newIndex); + } + + return new Index(newIndexList); + } + + + public Index putNodeAll(TreeNode node) { + List<String> keys = node.getAttributes().getKeys(); + TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexList = indexList; + + for (String key : keys) { + + String value = node.getAttributes().getString(key); + if (value == null) + continue; + + Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); + if (indexOp.isNone()) + continue; + + TreeMap<String, List<TreeNode>> index = indexOp.some(); + Option<List<TreeNode>> nodeListOp = index.get(value); + TreeMap<String, List<TreeNode>> newIndex = index; + + if (nodeListOp.isNone()) { + List<TreeNode> newNodeList = List.nil(); + newNodeList = newNodeList.cons(node); + newIndex = newIndex.set(value, newNodeList); + } else { + List<TreeNode> newNodeList = nodeListOp.some(); + newNodeList = newNodeList.cons(node); + newIndex = newIndex.set(value, newNodeList); + } + + newIndexList = newIndexList.set(key, newIndex); + } + return new Index(newIndexList); + } + + public List<TreeNode> get(String key, String value) { + Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); + if (indexOp.isNone()) + return List.nil(); + + TreeMap<String, List<TreeNode>> index = indexOp.some(); + Option<List<TreeNode>> nodeListOp = index.get(value); + + if (nodeListOp.isNone()) + return List.nil(); + + return nodeListOp.some(); + } + + + private TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { + return indexList; + } + +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexManager.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexManager.java Sat Nov 22 14:46:44 2014 +0900 @@ -1,8 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; -import fj.data.List; -import fj.data.TreeMap; + import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; @@ -19,7 +18,7 @@ this.reservation = reservation; } - public void commit(TreeMap<String, TreeMap<String, List<TreeNode>>> index){ + public void commit(Index index){ TreeContext tc = reservation.get(); ChangeSet cs = tc.getChangeSet(); TreeNode root = cs.getRoot();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/ParentIndex.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/ParentIndex.java Sat Nov 22 14:46:44 2014 +0900 @@ -1,6 +1,9 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; +import java.util.Iterator; + import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.TreeMapOrd; import fj.data.Option; import fj.data.TreeMap; @@ -40,4 +43,26 @@ return new ParentIndex(newParentIndex); } + public ParentIndex deleteAllChildren(TreeNode parentNode) { + TreeNodeChildren children = parentNode.getChildren(); + Iterator<TreeNode> childrenIterator = children.iterator(); + TreeMap<TreeNode, TreeNode> newParentIndex = parentIndex; + for (; childrenIterator.hasNext();) { + TreeNode child = childrenIterator.next(); + newParentIndex = newParentIndex.delete(child); + } + return new ParentIndex(newParentIndex); + } + + public ParentIndex addAllChildren(TreeNode parentNode) { + TreeNodeChildren children = parentNode.getChildren(); + Iterator<TreeNode> childrenIterator = children.iterator(); + TreeMap<TreeNode, TreeNode> newParentIndex = parentIndex; + for (; childrenIterator.hasNext();) { + TreeNode child = childrenIterator.next(); + newParentIndex = newParentIndex.set(child, parentNode); + } + return new ParentIndex(newParentIndex); + } + }
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/ParentIndexTest.java Sat Nov 22 12:54:28 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/ParentIndexTest.java Sat Nov 22 14:46:44 2014 +0900 @@ -12,11 +12,8 @@ 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; -import fj.data.TreeMap; public class ParentIndexTest {