Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 141:3071b1a471fd
add getKeys
author | one |
---|---|
date | Tue, 11 Nov 2014 18:57:52 +0900 |
parents | 99bda30ea72c |
children | ef183969bf31 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNodeAttributes.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeAttribute.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/query/PathNodeIterator.java src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/AddChildrenIndexTest.java |
diffstat | 6 files changed, 33 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNodeAttributes.java Fri Nov 07 02:20:31 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNodeAttributes.java Tue Nov 11 18:57:52 2014 +0900 @@ -2,6 +2,7 @@ import java.nio.ByteBuffer; +import fj.data.List; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Attributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; @@ -12,4 +13,5 @@ public Either<Error,TreeNode> delete(String key); public Either<Error,TreeNode> put(String key,ByteBuffer value); public TreeMap<String,ByteBuffer> getAttributesAsRawMap(); + public List<String> getKeys(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Fri Nov 07 02:20:31 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Tue Nov 11 18:57:52 2014 +0900 @@ -46,17 +46,6 @@ return new DefaultTreeNode(); } - /*public DefaultNode getWrap() - { - return wrap; - }*/ - - /*@Override - public Node getAsNode() - { - return getWrap(); - } - */ public DefaultTreeNode clone() { return new DefaultTreeNode(children,attrs);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeAttribute.java Fri Nov 07 02:20:31 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeAttribute.java Tue Nov 11 18:57:52 2014 +0900 @@ -87,4 +87,9 @@ return new String(attribute.array()); return null; } + + @Override + public List<String> getKeys() { + return attrs.keys(); + } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Fri Nov 07 02:20:31 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Tue Nov 11 18:57:52 2014 +0900 @@ -8,6 +8,8 @@ import fj.data.Option; 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.NulIterator; +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.util.Pair; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIterator; @@ -66,25 +68,25 @@ TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = this.index.get(key).some(); - Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex.get(searchValue); + Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex.get(searchValue); - if (opList.isNone()) - return null;// 空のIteratorを返す + if (opList.isNone()) + return new NulIterator<Pair<TreeNode, NodePath>>();// 空のIteratorを返す - List<Pair<TreeNode, NodePath>> list = opList.some(); - NodePath targetNodePath = subTree.right(); - List<Pair<TreeNode, NodePath>> filteredList = List.nil(); - - for (Pair<TreeNode, NodePath> pair : list) { - NodePath compareNodePath = pair.right(); - if (targetNodePath.compare(compareNodePath)) - filteredList = filteredList.cons(pair); - } - - return filteredList.iterator(); + List<Pair<TreeNode, NodePath>> list = opList.some(); + NodePath targetNodePath = subTree.right(); + List<Pair<TreeNode, NodePath>> filteredList = List.nil(); + + for (Pair<TreeNode, NodePath> pair : list) { + NodePath compareNodePath = pair.right(); + if (targetNodePath.compare(compareNodePath)) + filteredList = filteredList.cons(pair); + } + + return filteredList.iterator(); } else { - final PathNodeIterator itNode = new PathNodeIterator(subTree.left()); + final PathNodeIterator itNode = new PathNodeIterator(subTree); return new Iterator<Pair<TreeNode, NodePath>>() { private Pair<TreeNode, NodePath> matchPair = nextmatch(itNode); @@ -164,7 +166,7 @@ return filteredList.iterator(); } else { - final PathNodeIterator itNode = new PathNodeIterator(subTree.left()); + final PathNodeIterator itNode = new PathNodeIterator(subTree); return new Iterator<Pair<TreeNode, NodePath>>() { private Pair<TreeNode, NodePath> matchPair = nextmatch(itNode); @@ -210,14 +212,14 @@ Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex.get(searchValue); if (opList.isNone()) - return null;// 空のIteratorを返す + return new NulIterator<Pair<TreeNode, NodePath>>();// 空のIteratorを返す final List<Pair<TreeNode, NodePath>> list = opList.some(); return list.iterator(); } else { - - final PathNodeIterator itNode = new PathNodeIterator(node); + Pair<TreeNode, NodePath> pair = new Pair<TreeNode, NodePath>(node, new DefaultNodePath()); + final PathNodeIterator itNode = new PathNodeIterator(pair); return new Iterator<Pair<TreeNode, NodePath>>() { private Pair<TreeNode, NodePath> matchPair = nextmatch(itNode); @@ -311,8 +313,8 @@ return valueList.iterator(); } else { - - final PathNodeIterator itNode = new PathNodeIterator(node); + Pair<TreeNode, NodePath> pair = new Pair<TreeNode, NodePath>(node, new DefaultNodePath()); + final PathNodeIterator itNode = new PathNodeIterator(pair); return new Iterator<Pair<TreeNode, NodePath>>() { private Pair<TreeNode, NodePath> matchPair = nextmatch(itNode);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/query/PathNodeIterator.java Fri Nov 07 02:20:31 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/query/PathNodeIterator.java Tue Nov 11 18:57:52 2014 +0900 @@ -25,9 +25,9 @@ * otherwise traverse tree and create index * * */ - public PathNodeIterator(TreeNode root) { - this.root = root; - path = new DefaultNodePath(); + public PathNodeIterator(Pair<TreeNode,NodePath> pair) { + this.root = pair.left(); + path = pair.right(); node = root; }
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/AddChildrenIndexTest.java Fri Nov 07 02:20:31 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/AddChildrenIndexTest.java Tue Nov 11 18:57:52 2014 +0900 @@ -59,7 +59,6 @@ InterfaceTraverser newIfTraverser = tree.getTraverser(); TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = newIfTraverser.getIndex(); - Assert.assertTrue(newIndex.get(key).some().get("<-1,0,0>").isNone()); Assert.assertEquals(newIndex.get(key).some().get("<-1,0,1>").some().head().right().toString(),"<-1,0,2>"); }