Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 170:383b08d1711c
change Index form TreeMap<String TreeMap<String , List<TreeNode>>> → TreeMap<String TreeMap<String , TreeMap<TreeNode,TreeNode>>>
author | one |
---|---|
date | Fri, 26 Dec 2014 03:58:47 +0900 |
parents | 3cd075a445bf |
children | 624a7e6a3f75 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultChangeSet.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/store/index/Index.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexCreater.java |
diffstat | 5 files changed, 121 insertions(+), 114 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Fri Dec 26 01:43:54 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Fri Dec 26 03:58:47 2014 +0900 @@ -80,7 +80,7 @@ }; DefaultTreeNode root = new DefaultTreeNode(); - TreeMap<String, TreeMap<String, List<TreeNode>>> indexList = new Index().getIndex(); + TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexList = new Index().getIndex(); TreeMap<TreeNode, TreeNode> parentIndex = new ParentIndex().getParentIndex(); ChangeSet set = new DefaultChangeSet(root,null,list,uuid,name,0,indexList,parentIndex); DefaultTreeContext tc = new DefaultTreeContext(root,set);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultChangeSet.java Fri Dec 26 01:43:54 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultChangeSet.java Fri Dec 26 03:58:47 2014 +0900 @@ -1,6 +1,5 @@ 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; @@ -17,10 +16,10 @@ private final String uuid; private final String treeName; private final long revision; - private final TreeMap<String, TreeMap<String, List<TreeNode>>> indexList; + private final TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexList; private final TreeMap<TreeNode, TreeNode> parentIndex; - public DefaultChangeSet(TreeNode _node,ChangeSet _prev,ChangeList _log,String _uuid, String _treeName, long _revision,TreeMap<String, TreeMap<String, List<TreeNode>>> indexList, + public DefaultChangeSet(TreeNode _node,ChangeSet _prev,ChangeList _log,String _uuid, String _treeName, long _revision, TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexList, TreeMap<TreeNode, TreeNode> parentIndex) { this.root = _node;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Fri Dec 26 01:43:54 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Fri Dec 26 03:58:47 2014 +0900 @@ -8,7 +8,6 @@ import java.util.Iterator; import fj.data.List; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NulIterator; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIterator; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.Query; @@ -66,15 +65,15 @@ IndexCreater creater = new IndexCreater(node); long t2 = System.currentTimeMillis(); System.out.println("createIndex time = " + (t2 - t1)); - File file = new File("./time/createParentIndex"); - try { - PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file,true))); - pw.println((t2 - t1)); - pw.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } +// File file = new File("./time/createParentIndex"); +// try { +// PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file,true))); +// pw.println((t2 - t1)); +// pw.close(); +// } catch (IOException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } index = creater.getIndex(); parentIndex = creater.getParentIndex(); } @@ -93,16 +92,14 @@ * indexを使って取ってきたNodeのPathと、subTreeのPathを先頭から1つずつ比較し、 * indexから取ってきたNodeのPathが一致した場合、そのNodeを返す */ - List<TreeNode> nodeList = index.get(key, searchValue); - if (nodeList != null && useIndex) { - - if (nodeList.isEmpty()) - return new NulIterator<TreeNode>();// 空のIteratorを返す + Iterator<TreeNode> nodeIterator = index.get(key, searchValue); + if (nodeIterator.hasNext() && useIndex) { // ここでNode以下にあるか調べる List<TreeNode> filteredList = List.nil(); - for (TreeNode targetNode : nodeList) { + for (;nodeIterator.hasNext();) { + TreeNode targetNode = nodeIterator.next(); TreeNode parent = targetNode; while (parent != null) { parent = parentIndex.get(parent); @@ -224,9 +221,9 @@ public Iterator<TreeNode> find(final Query query, final String key, String searchValue) { - List<TreeNode> nodeList = index.get(key, searchValue); - if (nodeList != null && useIndex) { - return nodeList.iterator(); + Iterator<TreeNode> nodeIterator = index.get(key, searchValue); + if (nodeIterator.hasNext() && useIndex) { + return nodeIterator; } else { final PathNodeIterator itNode = new PathNodeIterator(node); @@ -243,7 +240,7 @@ if (value != null) index = index.set(key, value, targetNode); } - if (parentUpdateFlag) + if (parentUpdateFlag); // parentIndex = parentIndex.set(targetNode); if (query.condition(targetNode)) return targetNode; @@ -299,7 +296,7 @@ if (value != null) index = index.set(key, value, targetNode); } - if (parentUpdateFlag) + if (parentUpdateFlag); // parentIndex = parentIndex.set(targetNode); if (query.condition(targetNode)) return targetNode;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java Fri Dec 26 01:43:54 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java Fri Dec 26 03:58:47 2014 +0900 @@ -4,126 +4,137 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NulIterator; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.TreeMapOrd; 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; + TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexList; public Index() { - this.indexList = TreeMap.empty(Ord.stringOrd); + indexList = TreeMap.empty(Ord.stringOrd); } - public Index(TreeMap<String, TreeMap<String, List<TreeNode>>> indexList) { + public Index(TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexList) { this.indexList = indexList; } - public Index set(String key, String value, TreeNode node) { - Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); + + Option<TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexOp = indexList.get(key); if (indexOp.isNone()) { - TreeMap<String, List<TreeNode>> index = TreeMap.empty(Ord.stringOrd); - List<TreeNode> nodeList = List.nil(); - List<TreeNode> newNodeList = nodeList.cons(node); - TreeMap<String, List<TreeNode>> newIndex = index.set(value, newNodeList); + TreeMap<String, TreeMap<TreeNode, TreeNode>> index = TreeMap.empty(Ord.stringOrd); + TreeMap<TreeNode, TreeNode> nodeMap = TreeMap.empty(TreeMapOrd.treeNodeOrd); + nodeMap = nodeMap.set(node, node); + TreeMap<String, TreeMap<TreeNode, TreeNode>> newIndex = index.set(value, nodeMap); indexList = indexList.set(key, newIndex); return this; } - TreeMap<String, List<TreeNode>> index = indexOp.some(); - Option<List<TreeNode>> nodeListOp = index.get(value); + TreeMap<String, TreeMap<TreeNode, TreeNode>> index = indexOp.some(); + Option<TreeMap<TreeNode, TreeNode>> nodeMapOp = index.get(value); - List<TreeNode> newNodeList; - if (nodeListOp.isSome()) { - List<TreeNode> nodeList = nodeListOp.some(); - newNodeList = nodeList.cons(node); + TreeMap<TreeNode, TreeNode> newNodeMap; + if (nodeMapOp.isSome()) { + TreeMap<TreeNode, TreeNode> nodeMap = nodeMapOp.some(); + newNodeMap = nodeMap.set(node, node); } else { - List<TreeNode> nodeList = List.nil(); - newNodeList = nodeList.cons(node); + TreeMap<TreeNode, TreeNode> nodeMap = TreeMap.empty(TreeMapOrd.treeNodeOrd); + newNodeMap = nodeMap.set(node, node); } - TreeMap<String, List<TreeNode>> newIndex = index.set(value, newNodeList); + TreeMap<String, TreeMap<TreeNode, TreeNode>> newIndex = index.set(value, newNodeMap); indexList = indexList.set(key, newIndex); return this; } - + + // 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 Iterator<TreeNode> get(String key, String value) { -// 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); -// } + Option<TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexOp = indexList.get(key); + if (indexOp.isNone()) + return new NulIterator<TreeNode>(); + + TreeMap<String, TreeMap<TreeNode, TreeNode>> index = indexOp.some(); + Option<TreeMap<TreeNode, TreeNode>> nodeMapOp = index.get(value); + + if (nodeMapOp.isNone()) + return new NulIterator<TreeNode>(); + + Iterator<P2<TreeNode, TreeNode>> mapIterator = nodeMapOp.some().iterator(); + return new Iterator<TreeNode>() { - + @Override + public boolean hasNext() { + return mapIterator.hasNext(); + } - public List<TreeNode> get(String key, String value) { + @Override + public TreeNode next() { + return mapIterator.next()._1(); + } - Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); + }; + } + + public Iterator<TreeNode> getAll(String key) { + + Option<TreeMap<String, TreeMap<TreeNode, TreeNode>>> indexOp = indexList.get(key); if (indexOp.isNone()) return null; - TreeMap<String, List<TreeNode>> index = indexOp.some(); - Option<List<TreeNode>> nodeListOp = index.get(value); - - if (nodeListOp.isNone()) - return List.nil(); - - return nodeListOp.some(); - } - - public Iterator<TreeNode> getAll(String key){ - - Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); - if (indexOp.isNone()) - return null; - - final TreeMap<String, List<TreeNode>> index = indexOp.some(); + final TreeMap<String, TreeMap<TreeNode, TreeNode>> index = indexOp.some(); if (!index.isEmpty()) return new NulIterator<TreeNode>(); - - return new Iterator<TreeNode>(){ - - Iterator<P2<String, List<TreeNode>>> treeMapIterator = index.iterator(); - List<TreeNode> nodeList = List.nil(); + return new Iterator<TreeNode>() { + + Iterator<P2<String, TreeMap<TreeNode, TreeNode>>> treeMapIterator = index.iterator(); + Iterator<P2<TreeNode, TreeNode>> nodeIterator = new NulIterator<P2<TreeNode, TreeNode>>(); TreeNode node; - + @Override public boolean hasNext() { - - if (nodeList.isNotEmpty()) { - node = nodeList.head(); - nodeList = nodeList.tail(); + + if (nodeIterator.hasNext()) { + node = nodeIterator.next()._1(); return true; } - - for (;treeMapIterator.hasNext();) { - nodeList = treeMapIterator.next()._2(); - node = nodeList.head(); - nodeList = nodeList.tail(); - return true; + + for (; treeMapIterator.hasNext();) { + TreeMap<TreeNode, TreeNode> nodeMap = treeMapIterator.next()._2(); + nodeIterator = nodeMap.iterator(); + if (nodeIterator.hasNext()) { + node = nodeIterator.next()._1(); + return true; + } } return false; } @@ -132,13 +143,13 @@ public TreeNode next() { return node; } - + }; - + } - - public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { + + public TreeMap<String, TreeMap<String, TreeMap<TreeNode, TreeNode>>> getIndex() { return indexList; } - + }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexCreater.java Fri Dec 26 01:43:54 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexCreater.java Fri Dec 26 03:58:47 2014 +0900 @@ -22,6 +22,12 @@ this.node = rootNode; while (node != null) { TreeNode targetNode = node; + List<String> keys = targetNode.getAttributes().getKeys(); + for (String key : keys) { + String value = targetNode.getAttributes().getString(key); + if (value != null) + index = index.set(key, value, targetNode); + } if (node.getChildren().size() > 0) { nodeStack.push(node); TreeNode parent = node; @@ -63,12 +69,6 @@ searchStack.push(++childNumber); } } - List<String> keys = targetNode.getAttributes().getKeys(); - for (String key : keys) { - String value = targetNode.getAttributes().getString(key); - if (value != null) - index = index.set(key, value, targetNode); - } } }