Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 127:b2c1fd513feb
push index thread add read log
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Thu Oct 09 18:15:14 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Mon Oct 13 03:22:16 2014 +0900 @@ -79,6 +79,11 @@ public String getTreeName() { return name; } + + @Override + public int getLogSize() { + return 0; + } }; DefaultTreeNode root = new DefaultTreeNode();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java Thu Oct 09 18:15:14 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java Mon Oct 13 03:22:16 2014 +0900 @@ -1,12 +1,16 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; +import org.omg.CORBA.TCKind; + 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.store.ChangeSet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; 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.AtomicReservableReference; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultJungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTransactionManager; @@ -71,8 +75,8 @@ ChangeSet cs = tc.getChangeSet(); TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = cs.getIndex(); if (index != null) - return new InterfaceTraverser(getRootNode(), index, getTreeEditor()); - return new InterfaceTraverser(getRootNode(),getTreeEditor()); + return new InterfaceTraverser(getRootNode(), index, getIndexTreeEditor()); + return new InterfaceTraverser(getRootNode(),getIndexTreeEditor()); } @Override @@ -81,4 +85,21 @@ ChangeSet cs = tc.getChangeSet(); return cs.getIndex(); } + + @Override + public int getLogSize(){ + TreeContext tc = repository.get(); + ChangeSet cs = tc.getChangeSet(); + ChangeList cl = cs.getChangeList(); + return cl.getLogSize(); + } + + @Override + public Iterable<TreeOperation> getLog() { + TreeContext tc = repository.get(); + ChangeSet cs = tc.getChangeSet(); + return cs.getOperations(); + } + + }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Thu Oct 09 18:15:14 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Mon Oct 13 03:22:16 2014 +0900 @@ -3,8 +3,11 @@ 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.NodePath; 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.Pair; @@ -17,4 +20,6 @@ public TreeNode getRootNode(); public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex(); public IndexJungleTreeEditor getIndexTreeEditor(); + public int getLogSize(); + public Iterable<TreeOperation> getLog(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/persistent/ChangeList.java Thu Oct 09 18:15:14 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/persistent/ChangeList.java Mon Oct 13 03:22:16 2014 +0900 @@ -6,4 +6,5 @@ { public String uuid(); public String getTreeName(); + public int getLogSize(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTransactionManager.java Thu Oct 09 18:15:14 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTransactionManager.java Mon Oct 13 03:22:16 2014 +0900 @@ -56,6 +56,10 @@ public String uuid(){ return uuid; } + @Override + public int getLogSize() { + return _log.length(); + } }; DefaultChangeSet newCs = new DefaultChangeSet(_newRoot,cs,list,uuid, _treeName, nextRevision,index);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java Thu Oct 09 18:15:14 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java Mon Oct 13 03:22:16 2014 +0900 @@ -171,4 +171,5 @@ { return root; } + } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Thu Oct 09 18:15:14 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Mon Oct 13 03:22:16 2014 +0900 @@ -10,15 +10,36 @@ 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.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; 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; public class InterfaceTraverser { - InterfaceTraverser traverser; + //InterfaceTraverser traverser; TreeNode node; TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; + IndexJungleTreeEditor editor; + + public InterfaceTraverser(TreeNode _root, IndexJungleTreeEditor editor) { + this.node = _root; + this.index = TreeMap.empty(Ord.stringOrd); + this.editor = editor; + } + + public InterfaceTraverser( + TreeNode _root, + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index, + IndexJungleTreeEditor editor) { + this.node = _root; + this.index = index; + this.editor = editor; + } + + public IndexJungleTreeEditor getEditor() { + return editor; + } public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { return index; @@ -29,28 +50,11 @@ this.index = index; } - - - JungleTreeEditor editor; - - public InterfaceTraverser(TreeNode _root, JungleTreeEditor editor) { - this.node = _root; - this.index = TreeMap.empty(Ord.stringOrd); - this.editor = editor; - } - - public InterfaceTraverser( - TreeNode _root, - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index, - JungleTreeEditor editor) { - this.node = _root; - this.index = index; - this.editor = editor; - } - + + public InterfaceTraverser getTraverser(JungleTree tree) { return new InterfaceTraverser(tree.getRootNode(), tree.getIndex(), - tree.getTreeEditor()); + tree.getIndexTreeEditor()); } public void set(TreeNode root) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/query/PathNodeIndexIterator.java Mon Oct 13 03:22:16 2014 +0900 @@ -0,0 +1,99 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query; + +import java.util.Iterator; +import java.util.Stack; + +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.DefaultNodePath; +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.Pair; + +public class PathNodeIndexIterator implements Iterator<Pair<TreeNode, NodePath>> { + + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; + NodePath path; + TreeNode root; + TreeNode node; + int childNumber; + private TreeNodeChildren children; + private Stack<TreeNode> nodeStack = new Stack<TreeNode>(); + private Stack<Integer> searchStack = new Stack<Integer>(); + + /* + * get queryIndexCondition from query + * if already index exists, use index + * otherwise traverse tree and create index + * + * */ + public PathNodeIndexIterator(TreeNode root, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { + this.root = root; + this.index = index; + path = new DefaultNodePath(); + node = root; + } + + @Override + public boolean hasNext() { + return node != null; + } + + @Override + public Pair<TreeNode, NodePath> next() { + TreeNode now = node; + NodePath currentPath = path; + if (node.getChildren().size() > 0) { // + nodeStack.push(node); + path = path.add(0); + children = node.getChildren(); + node = children.at(0).b(); + childNumber = 1; + searchStack.push(childNumber); + } else if (node == root) { + node = null; // no more node + children = null; + return new Pair<TreeNode, NodePath>(now, currentPath); + }else if (children != null && children.size() > childNumber) { + childNumber = searchStack.pop(); + node = children.at(childNumber).b(); + path = path.tail().add(childNumber); + searchStack.push(++childNumber); + } else { + path = path.tail(); + node = nodeStack.pop(); + children = node.getChildren(); + childNumber = searchStack.pop(); + for (; children.size() == childNumber;) { + if (node == root) { + node = null; // no more node + children = null; + return new Pair<TreeNode, NodePath>(now, currentPath); + } + path = path.tail(); + node = nodeStack.pop(); + children = node.getChildren(); + childNumber = searchStack.pop(); + } + if (node != null && childNumber < children.size()) { + path = path.add(childNumber); + nodeStack.push(node); + node = children.at(childNumber).b(); + searchStack.push(++childNumber); + } + } + System.out.println("path = " + path.toString()); + return new Pair<TreeNode, NodePath>(now, currentPath); + } + + @Override + public void remove() { + // TODO Auto-generated method stub + + } + + public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { + return index; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexPushThread.java Mon Oct 13 03:22:16 2014 +0900 @@ -0,0 +1,82 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; + +import java.nio.ByteBuffer; + +import javax.swing.tree.DefaultTreeCellEditor.EditorContainer; + +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.ChangeSet; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; +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.util.Pair; +import fj.data.List; +import fj.data.TreeMap; + +public class IndexPushThread extends Thread { + + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; + JungleTree tree; + IndexJungleTreeEditor editor; + int logSize; + + public IndexPushThread( + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index, + JungleTree tree,IndexJungleTreeEditor editor, int logSize) { + this.index = index; + this.tree = tree; + this.editor = editor; + this.logSize = logSize; + } + + public void run() { + while (true) { + + if (logSize == tree.getLogSize()) { + editor.setIndex(index); + if (editor.success().isB()) + break; + } else { + editor = tree.getIndexTreeEditor(); + Iterable<TreeOperation> Changeset = tree.getLog(); + int loopCount = 0; + + for(TreeOperation treeOp : Changeset) { + loopCount++; + if (loopCount >= logSize) { + NodePath path = treeOp.getNodePath(); + NodeOperation NodeOperation = treeOp.getNodeOperation(); + Command c = NodeOperation.getCommand(); + + switch (c) { + case PUT_ATTRIBUTE://ここ以下でIndexEditorを使ってindexの更新を行う + String key = NodeOperation.getKey(); + ByteBuffer value = NodeOperation.getValue(); + + //return editor.putAttribute(path, key, value); + case DELETE_ATTRIBUTE: + key = NodeOperation.getKey(); + //return editor.deleteAttribute(path, key); + case APPEND_CHILD: + //return editor.addNewChildAt(path, pos); + case DELETE_CHILD: + //return editor.deleteChildAt(path, 0); + } + } + } + + logSize = loopCount; + editor.setIndex(index); + if (editor.success().isB()) + break; + + } + editor = tree.getIndexTreeEditor(); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/ip/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/IndexCommitTest.java Mon Oct 13 03:22:16 2014 +0900 @@ -0,0 +1,120 @@ +package ip.ac.u_ryukyu.ie.cr.tatsuki.jungle.index; + +import java.util.Iterator; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; +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.NodePath; +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.transaction.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; +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.Pair; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.IndexPushThread; +import junit.framework.Assert; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; + +import java.nio.ByteBuffer; + +import org.junit.Test; +import org.junit.experimental.theories.suppliers.TestedOn; + +import fj.data.List; +import fj.data.Option; +import fj.data.TreeMap; + +public class IndexCommitTest { + + @Test + public void IndexCommitTest() throws InterruptedException { + + Jungle jungle = new DefaultJungle(null, "hogehoge", + new DefaultTreeEditor(new DefaultTraverser())); + jungle.createNewTree("tree"); + JungleTree tree = jungle.getTreeByName("tree"); + createTree(tree); + tree.getRootNode(); + InterfaceTraverser ifTraverser = tree.getTraverser(); + + Iterator<Pair<TreeNode, NodePath>> searchNode = ifTraverser.find(( + TreeNode node) -> { + ByteBuffer attribute = node.getAttributes().get(key); + if (attribute != null) { + byte[] byteAttribute = attribute.array(); + String str = new String(byteAttribute); + System.out.println("attribute = " + str); + return str.equals("<-1,0,1>"); + } + return false; + }, key, "<-1,0,1>"); + + //check index + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = ifTraverser.getIndex(); + Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> opIndex = index.get(key); + Assert.assertTrue(!opIndex.isNone()); + TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = opIndex.some(); + Assert.assertTrue(!innerIndex.get("<-1,0,0>").isNone()); + + IndexPushThread wt = new IndexPushThread(index, tree,ifTraverser.getEditor(), 0); + wt.start(); + wt.join(); + JungleTree newTree = jungle.getTreeByName("tree"); + InterfaceTraverser newIfTraverser = newTree.getTraverser(); + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = newIfTraverser.getIndex(); + Assert.assertFalse(newIndex.isEmpty()); + + } + + public boolean compare(TreeNode compareNode, String compareAttribute) { + String labName = compareNode.getAttributes().getString(key); + if (labName.equals(compareAttribute)) + return true; + return false; + } + + public static String key = "KEY"; + public static DefaultTreeNode factory = new DefaultTreeNode(); + + public void createTree(JungleTree tree) { + NodePath root = new DefaultNodePath(); + createChildren(tree, root, 0); + + for (int x = 0; x < 2; x++) { + createChildren(tree, root.add(0), x); + for (int y = 0; y < 2; y++) { + createChildren(tree, root.add(0).add(x), y); + } + } + + } + + public void createChildren(JungleTree tree, NodePath root, int num) { + JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成 + Either<Error, JungleTreeEditor> either = editor + .addNewChildAt(root, num); // 新しく入れるところへのパス + if (either.isA()) { + Assert.fail(); + } + editor = either.b(); + either = editor.success(); + if (either.isA()) { + Assert.fail(); + } + NodePath childPath = root.add(num); + editor = tree.getTreeEditor(); + NodePath attribute = root.add(num); + System.out.println(attribute.toString()); + either = editor.putAttribute(childPath, key, + ByteBuffer.wrap(attribute.toString().getBytes())); + if (either.isA()) { + Assert.fail(); + } + editor = either.b(); + either = editor.success(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/ip/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/IndexTest.java Mon Oct 13 03:22:16 2014 +0900 @@ -0,0 +1,105 @@ +package ip.ac.u_ryukyu.ie.cr.tatsuki.jungle.index; + +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeAttributes; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; +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.Pair; + +import org.junit.Assert; +import org.junit.Test; + +import fj.Ord; +import fj.data.List; +import fj.data.Option; +import fj.data.TreeMap; + +public class IndexTest { + + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = TreeMap + .empty(Ord.stringOrd); + + @Test + public void IndexTest() { + + NodePath path = new DefaultNodePath(); + TreeNode node = createTree(3, 0, 3, path); + TreeMap<String, List<Pair<TreeNode, NodePath>>> map = index.get(key).some(); + Option<List<Pair<TreeNode, NodePath>>> opList = map.get("<-1,0,0,2>"); + List<Pair<TreeNode, NodePath>> list = opList.some(); + Pair<TreeNode, NodePath> Pair = list.head(); + NodePath newPath = Pair.right(); + String pathStr = newPath.toString(); + Assert.assertEquals(pathStr,"<-1,0,0,2>"); + System.out.println("aaa"); + } + + public static String key = "KEY"; + public static ByteBuffer value = ByteBuffer.wrap(key.getBytes()); + public static DefaultTreeNode factory = new DefaultTreeNode(); + + public TreeNode createTree(int _curX, int _curY, int _maxHeight, + NodePath _address) { + TreeNode parent = factory.createNewNode(); + Either<Error, TreeNode> either = parent.getAttributes().put(key,ByteBuffer.wrap(_address.toString().getBytes())); + if (either.isA()) { + Assert.fail(); + } + editIndex(parent, _address, _address.toString(), key); + parent = either.b(); + + if (_curY == _maxHeight) { + return parent; + } + + for (int i = 0; i < _curY + 1; i++) { + TreeNode ch = createTree(i, _curY + 1, _maxHeight, _address.add(i)); + either = parent.getChildren().addNewChildAt(i, ch); + if (either.isA()) { + Assert.fail(); + } + + parent = either.b(); + } + + return parent; + } + + + public void editIndex(TreeNode node, NodePath path, String attribute,String key) { + + Pair<TreeNode, NodePath> pair = new Pair<TreeNode, NodePath>(node, path); + Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> opAttributeList = index.get(key); + + if (opAttributeList.isNone()) { + TreeMap<String, List<Pair<TreeNode, NodePath>>> nodeIndex = TreeMap.empty(Ord.stringOrd); + List<Pair<TreeNode, NodePath>> list = List.nil(); + list = list.cons(pair); + nodeIndex = nodeIndex.set(attribute, list); + index = index.set(key, nodeIndex); + } else { + TreeMap<String, List<Pair<TreeNode, NodePath>>> indexMap = opAttributeList.some(); + Option<List<Pair<TreeNode, NodePath>>> opNodeIndex = indexMap.get(attribute); + + if (opNodeIndex.isNone()) { + List<Pair<TreeNode, NodePath>> pairList = List.nil(); + pairList = pairList.cons(pair); + indexMap = indexMap.set(attribute, pairList); + + } else { + List<Pair<TreeNode, NodePath>> pairList = opNodeIndex.some(); + pairList = pairList.cons(pair); + indexMap = indexMap.set(attribute, pairList); + } + index = index.set(key, indexMap); + } + System.out.println(attribute); + + } + +}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/IndexTest.java Thu Oct 09 18:15:14 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.functionaljava; - -import java.nio.ByteBuffer; - -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeAttributes; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; -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.Pair; - -import org.junit.Assert; -import org.junit.Test; - -import fj.Ord; -import fj.data.List; -import fj.data.Option; -import fj.data.TreeMap; - -public class IndexTest { - - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = TreeMap - .empty(Ord.stringOrd); - - @Test - public void IndexTest() { - - NodePath path = new DefaultNodePath(); - TreeNode node = createTree(3, 0, 3, path); - TreeMap<String, List<Pair<TreeNode, NodePath>>> map = index.get(key).some(); - Option<List<Pair<TreeNode, NodePath>>> opList = map.get("<-1,0,0,2>"); - List<Pair<TreeNode, NodePath>> list = opList.some(); - Pair<TreeNode, NodePath> Pair = list.head(); - NodePath newPath = Pair.right(); - String pathStr = newPath.toString(); - Assert.assertEquals(pathStr,"<-1,0,0,2>"); - System.out.println("aaa"); - } - - public static String key = "KEY"; - public static ByteBuffer value = ByteBuffer.wrap(key.getBytes()); - public static DefaultTreeNode factory = new DefaultTreeNode(); - - public TreeNode createTree(int _curX, int _curY, int _maxHeight, - NodePath _address) { - TreeNode parent = factory.createNewNode(); - Either<Error, TreeNode> either = parent.getAttributes().put(key,ByteBuffer.wrap(_address.toString().getBytes())); - if (either.isA()) { - Assert.fail(); - } - editIndex(parent, _address, _address.toString(), key); - parent = either.b(); - - if (_curY == _maxHeight) { - return parent; - } - - for (int i = 0; i < _curY + 1; i++) { - TreeNode ch = createTree(i, _curY + 1, _maxHeight, _address.add(i)); - either = parent.getChildren().addNewChildAt(i, ch); - if (either.isA()) { - Assert.fail(); - } - - parent = either.b(); - } - - return parent; - } - - - public void editIndex(TreeNode node, NodePath path, String attribute,String key) { - - Pair<TreeNode, NodePath> pair = new Pair<TreeNode, NodePath>(node, path); - Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> opAttributeList = index.get(key); - - if (opAttributeList.isNone()) { - TreeMap<String, List<Pair<TreeNode, NodePath>>> nodeIndex = TreeMap.empty(Ord.stringOrd); - List<Pair<TreeNode, NodePath>> list = List.nil(); - list = list.cons(pair); - nodeIndex = nodeIndex.set(attribute, list); - index = index.set(key, nodeIndex); - } else { - TreeMap<String, List<Pair<TreeNode, NodePath>>> indexMap = opAttributeList.some(); - Option<List<Pair<TreeNode, NodePath>>> opNodeIndex = indexMap.get(attribute); - - if (opNodeIndex.isNone()) { - List<Pair<TreeNode, NodePath>> pairList = List.nil(); - pairList = pairList.cons(pair); - indexMap = indexMap.set(attribute, pairList); - - } else { - List<Pair<TreeNode, NodePath>> pairList = opNodeIndex.some(); - pairList = pairList.cons(pair); - indexMap = indexMap.set(attribute, pairList); - } - index = index.set(key, indexMap); - } - System.out.println(attribute); - - } - -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/query/IndexPushThread.java Thu Oct 09 18:15:14 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.query; - -import javax.swing.tree.DefaultTreeCellEditor.EditorContainer; - -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.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; -import fj.data.List; -import fj.data.TreeMap; - -public class IndexPushThread extends Thread { - - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; - JungleTree tree; - - public IndexPushThread(TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index,JungleTree tree) { - this.index = index; - this.tree = tree; - } - - public void run() { - while (true) { - IndexJungleTreeEditor editor = tree.getIndexTreeEditor(); - editor.setIndex(index); - if (editor.success().isB()) - break; - } - } - -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/query/SearchQueryTest.java Thu Oct 09 18:15:14 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/query/SearchQueryTest.java Mon Oct 13 03:22:16 2014 +0900 @@ -20,6 +20,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIndexIterator; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.IndexPushThread; import org.junit.Assert; import org.junit.Test; @@ -36,6 +37,7 @@ jungle.createNewTree("tree"); JungleTree tree = jungle.getTreeByName("tree"); createTree(tree); + tree.getRootNode(); InterfaceTraverser ifTraverser = tree.getTraverser(); TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> cheackIndex = ifTraverser.getIndex(); Assert.assertTrue(cheackIndex.isEmpty()); @@ -63,15 +65,6 @@ Assert.assertTrue(!opIndex.isNone()); TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = opIndex.some(); Assert.assertTrue(!innerIndex.get("<-1,0,0>").isNone()); - - IndexPushThread wt = new IndexPushThread(index, tree); - wt.start(); - - JungleTree newTree = jungle.getTreeByName("tree"); - InterfaceTraverser newIfTraverser = newTree.getTraverser(); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = newIfTraverser.getIndex(); - Assert.assertFalse(newIndex.isEmpty()); - }