Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 137:7334f78a92c3
name changed find to findInSubTree
author | one |
---|---|
date | Mon, 27 Oct 2014 18:25:32 +0900 |
parents | 0f68cd7b2838 |
children | b998fdc99bc0 |
files | 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/store/index/PutIndexEditor.java |
diffstat | 2 files changed, 178 insertions(+), 166 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Sat Oct 25 16:50:32 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Mon Oct 27 18:25:32 2014 +0900 @@ -25,193 +25,207 @@ public class InterfaceTraverser { - //InterfaceTraverser traverser; - TreeNode node; - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; - IndexManager indexManager; + //InterfaceTraverser traverser; + TreeNode node; + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; + IndexManager indexManager; - public InterfaceTraverser(TreeNode _root, IndexManager indexManager) { - this.node = _root; - this.index = TreeMap.empty(Ord.stringOrd); - this.indexManager = indexManager; - } + public InterfaceTraverser(TreeNode _root, IndexManager indexManager) { + this.node = _root; + this.index = TreeMap.empty(Ord.stringOrd); + this.indexManager = indexManager; + } - public InterfaceTraverser( - TreeNode _root, - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index, - IndexManager indexManager) { - this.node = _root; - this.index = index; - this.indexManager = indexManager; - } + public InterfaceTraverser( + TreeNode _root, + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index, + IndexManager indexManager) { + this.node = _root; + this.index = index; + this.indexManager = indexManager; + } + + public void commitIndex(){ + indexManager.commit(index); + } - public void commitIndex(){ - indexManager.commit(index); - } - - public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { - return index; - } + public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { + return index; + } - public void setIndex( - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { - this.index = index; - } + public void setIndex( + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { + this.index = index; + } - - -/* public InterfaceTraverser getTraverser(JungleTree tree) { + + + /* public InterfaceTraverser getTraverser(JungleTree tree) { return new InterfaceTraverser(tree.getRootNode(), tree.getIndex(), tree.getIndexTreeEditor()); }*/ - public void set(TreeNode root) { - this.node = root; - } + public void set(TreeNode root) { + this.node = root; + } + + + /** + * subTree以下のNodeに対してKey,Valueのペアでindexを使って探索を行う + * @param query + * @param subTree + * @param key + * @param searchValue + * @return + */ + public Iterator<Pair<TreeNode, NodePath>> findInSubTree(Query query, TreeNode subTree, String key, String searchValue){ + /* + * indexを使って取ってきたNodeのPathと、subTreeのPathを先頭から1つずつ比較し、 + * indexから取ってきたNodeのPathが一致した場合、そのNodeを返す + */ + final PathNodeIterator itNode = new PathNodeIterator(subTree); + return new Iterator<Pair<TreeNode, NodePath>>() { + + private Pair<TreeNode, NodePath> matchPair = nextmatch(itNode); + + private Pair<TreeNode, NodePath> nextmatch( + PathNodeIterator itNode) { + for (; itNode.hasNext();) { + Pair<TreeNode, NodePath> pathNode = itNode.next(); + if (query.condition(pathNode.left())) + return pathNode; + } + return null; + } + + @Override + public boolean hasNext() { + if (matchPair == null) { + // index = itNode.getIndex(); + return false; + } + return true; + } + + @Override + public Pair<TreeNode, NodePath> next() { + Pair<TreeNode, NodePath> currentPair = matchPair; + matchPair = nextmatch(itNode); + return currentPair; + } + + @Override + public void remove() { + // TODO Auto-generated method stub + + } + + }; + + } - public Iterator<Pair<TreeNode, NodePath>> find(Query query, TreeNode searchNode, String key, String searchValue) { - - final PathNodeIterator itNode = new PathNodeIterator(searchNode); - return new Iterator<Pair<TreeNode, NodePath>>() { + public Iterator<Pair<TreeNode, NodePath>> find(Query query, String key, + String searchValue) { + + if (index.get(key).isSome()) { - private Pair<TreeNode, NodePath> matchPair = nextmatch(itNode); - - private Pair<TreeNode, NodePath> nextmatch( - PathNodeIterator itNode) { + TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = this.index + .get(key).some(); + Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex + .get(searchValue); - for (; itNode.hasNext();) { - Pair<TreeNode, NodePath> pathNode = itNode.next(); - if (query.condition(pathNode.left())) - return pathNode; - } - return null; - } + if (opList.isNone()) + return null;// 空のIteratorを返す + + final List<Pair<TreeNode, NodePath>> list = opList.some(); + return list.iterator(); - @Override - public boolean hasNext() { - if (matchPair == null) { -// index = itNode.getIndex(); - return false; - } - return true; - } + } else { - @Override - public Pair<TreeNode, NodePath> next() { - Pair<TreeNode, NodePath> currentPair = matchPair; - matchPair = nextmatch(itNode); - return currentPair; - } + final PathNodeIterator itNode = new PathNodeIterator(node); + return new Iterator<Pair<TreeNode, NodePath>>() { + + private Pair<TreeNode, NodePath> matchPair = nextmatch(itNode); - @Override - public void remove() { - // TODO Auto-generated method stub + private Pair<TreeNode, NodePath> nextmatch( + PathNodeIterator itNode) { - } + for (; itNode.hasNext();) { + Pair<TreeNode, NodePath> pathNode = itNode.next(); + String value = pathNode.left().getAttributes() + .getString(key); + Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> innerIndexOp = index + .get(key); + + if (value != null) { + if (innerIndexOp.isNone()) { - }; - - } - - public Iterator<Pair<TreeNode, NodePath>> find(Query query) { - return find(query, node, null, null); - } - - public Iterator<Pair<TreeNode, NodePath>> find(Query query, TreeNode searchNode) { - return find(query, searchNode, null, null); - } - - public Iterator<Pair<TreeNode, NodePath>> find(Query query, String key, String searchValue) { - - if (index.get(key).isSome()) { + TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = TreeMap + .empty(Ord.stringOrd); + List<Pair<TreeNode, NodePath>> list = List + .nil(); + list = list.cons(pathNode); + innerIndex = innerIndex.set(value, list); + index = index.set(key, innerIndex); - TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = this.index.get(key).some(); - Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex.get(searchValue); - - if (opList.isNone()) - return null;//空のIteratorを返す + } else { - final List<Pair<TreeNode, NodePath>> list = opList.some(); - return list.iterator(); - - } else { - - final PathNodeIterator itNode = new PathNodeIterator(node); - return new Iterator<Pair<TreeNode, NodePath>>() { - - private Pair<TreeNode, NodePath> matchPair = nextmatch(itNode); + TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = innerIndexOp + .some(); + Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex + .get(value); - private Pair<TreeNode, NodePath> nextmatch( - PathNodeIterator itNode) { - - for (; itNode.hasNext();) { - Pair<TreeNode, NodePath> pathNode = itNode.next(); - String value = pathNode.left().getAttributes().getString(key); - Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> innerIndexOp = index.get(key); + if (opList.isNone()) { - if (value != null) { - if (innerIndexOp.isNone()) { + List<Pair<TreeNode, NodePath>> list = List + .nil(); + list = list.cons(pathNode); + innerIndex = innerIndex.set(value, list); - TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = TreeMap.empty(Ord.stringOrd); - List<Pair<TreeNode, NodePath>> list = List.nil(); - list = list.cons(pathNode); - innerIndex = innerIndex.set(value, list); - index = index.set(key, innerIndex); + } else { - } else { + List<Pair<TreeNode, NodePath>> list = opList + .some(); + list = list.cons(pathNode); + innerIndex = innerIndex.set(value, list); - TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = innerIndexOp.some(); - Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex.get(value); - - if (opList.isNone()) { + } + index = index.set(key, innerIndex); - List<Pair<TreeNode, NodePath>> list = List.nil(); - list = list.cons(pathNode); - innerIndex = innerIndex.set(value, list); + } + } - } else { - - List<Pair<TreeNode, NodePath>> list = opList.some(); - list = list.cons(pathNode); - innerIndex = innerIndex.set(value, list); + if (query.condition(pathNode.left())) + return pathNode; + } + return null; + } - } - index = index.set(key, innerIndex); - - } - } - - if (query.condition(pathNode.left())) - return pathNode; - } - return null; - } + @Override + public boolean hasNext() { + if (matchPair == null) { + // index = itNode.getIndex(); + return false; + } + return true; + } - @Override - public boolean hasNext() { - if (matchPair == null) { -// index = itNode.getIndex(); - return false; - } - return true; - } + @Override + public Pair<TreeNode, NodePath> next() { + Pair<TreeNode, NodePath> currentPair = matchPair; + matchPair = nextmatch(itNode); + return currentPair; + } - @Override - public Pair<TreeNode, NodePath> next() { - Pair<TreeNode, NodePath> currentPair = matchPair; - matchPair = nextmatch(itNode); - return currentPair; - } + @Override + public void remove() { + // TODO Auto-generated method stub - @Override - public void remove() { - // TODO Auto-generated method stub + } - } - - }; - } - } + }; + } + } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/PutIndexEditor.java Sat Oct 25 16:50:32 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/PutIndexEditor.java Mon Oct 27 18:25:32 2014 +0900 @@ -6,7 +6,6 @@ import fj.data.List; import fj.data.Option; 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; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; @@ -17,7 +16,6 @@ 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 jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIndexIterator; import java.nio.ByteBuffer; @@ -32,9 +30,9 @@ TreeOperationLog log; public PutIndexEditor(String key, ByteBuffer attribute,NodePath path) { - this.key = key; - this.attribute = new String(attribute.array()); - this.path = path; + this.key = key; + this.attribute = new String(attribute.array()); + this.path = path; } @Override @@ -55,11 +53,11 @@ if (attribute != null) { if (innerIndexOp.isNone()) { -// TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = TreeMap.empty(Ord.stringOrd); -// List<Pair<TreeNode, NodePath>> list = List.nil(); -// list = list.cons(pathNode); -// innerIndex = innerIndex.set(attribute, list); -// TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = index.set(key, innerIndex); + TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = TreeMap.empty(Ord.stringOrd); + List<Pair<TreeNode, NodePath>> list = List.nil(); + list = list.cons(pathNode); + innerIndex = innerIndex.set(attribute, list); + TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = index.set(key, innerIndex); return index; } else {