Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 168:1749338f2366 util index
until index
author | one |
---|---|
date | Wed, 24 Dec 2014 16:14:42 +0900 |
parents | 6f7212808ad7 |
children | |
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/store/impl/TreeNode.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/transaction/DefaultTreeNode.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/ParentIndex.java |
diffstat | 6 files changed, 75 insertions(+), 94 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Wed Dec 24 15:05:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Wed Dec 24 16:14:42 2014 +0900 @@ -1,10 +1,10 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle; import java.util.Iterator; +import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; 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;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNode.java Wed Dec 24 15:05:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNode.java Wed Dec 24 16:14:42 2014 +0900 @@ -3,6 +3,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.AttributesContainer; public interface TreeNode extends AttributesContainer + { public TreeNodeChildren getChildren();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultChangeSet.java Wed Dec 24 15:05:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultChangeSet.java Wed Dec 24 16:14:42 2014 +0900 @@ -1,7 +1,8 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction; +import java.util.TreeMap; + 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;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Wed Dec 24 15:05:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Wed Dec 24 16:14:42 2014 +0900 @@ -8,7 +8,7 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; -public class DefaultTreeNode implements TreeNode +public class DefaultTreeNode implements TreeNode, Comparable { //private final DefaultNode wrap; private List<TreeNode> children; @@ -51,5 +51,11 @@ return new DefaultTreeNode(children,attrs); } + @Override + public int compareTo(Object o) { + + return o.hashCode() - this.hashCode(); + } + }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java Wed Dec 24 15:05:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java Wed Dec 24 16:14:42 2014 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; import java.util.Iterator; +import java.util.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NulIterator; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; @@ -8,121 +9,98 @@ 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); + this.indexList = new TreeMap<String, TreeMap<String, List<TreeNode>>>(); } public Index(TreeMap<String, TreeMap<String, List<TreeNode>>> indexList) { this.indexList = indexList; } - public Index set(String key, String value, TreeNode node) { - Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); - if (indexOp.isNone()) { - TreeMap<String, List<TreeNode>> index = TreeMap.empty(Ord.stringOrd); + TreeMap<String, List<TreeNode>> index = indexList.get(key); + if (index == null) { + index = new TreeMap<String, List<TreeNode>>(); List<TreeNode> nodeList = List.nil(); List<TreeNode> newNodeList = nodeList.cons(node); - TreeMap<String, List<TreeNode>> newIndex = index.set(value, newNodeList); - indexList = indexList.set(key, newIndex); + index.put(value, newNodeList); + indexList.put(key, index); return this; } - TreeMap<String, List<TreeNode>> index = indexOp.some(); - Option<List<TreeNode>> nodeListOp = index.get(value); - + List<TreeNode> nodeList = index.get(value); List<TreeNode> newNodeList; - if (nodeListOp.isSome()) { - List<TreeNode> nodeList = nodeListOp.some(); + if (nodeList != null) { newNodeList = nodeList.cons(node); } else { - List<TreeNode> nodeList = List.nil(); + nodeList = List.nil(); newNodeList = nodeList.cons(node); } - TreeMap<String, List<TreeNode>> newIndex = index.set(value, newNodeList); - indexList = indexList.set(key, newIndex); + index.put(value, newNodeList); + indexList.put(key, index); 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 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 List<TreeNode> get(String key, String value) { - Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); - if (indexOp.isNone()) + TreeMap<String, List<TreeNode>> index = indexList.get(key); + if (index == null) return null; - TreeMap<String, List<TreeNode>> index = indexOp.some(); - Option<List<TreeNode>> nodeListOp = index.get(value); + List<TreeNode> nodeList = index.get(value); - if (nodeListOp.isNone()) - return List.nil(); - - return nodeListOp.some(); + return nodeList; } - - public Iterator<TreeNode> getAll(String key){ + + public Iterator<TreeNode> getAll(String key) { - Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); - if (indexOp.isNone()) + TreeMap<String, List<TreeNode>> index = indexList.get(key); + if (index == null) return null; - - final TreeMap<String, List<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<TreeNode> treeMapIterator = index.get(key).iterator(); TreeNode node; - + @Override public boolean hasNext() { - - if (nodeList.isNotEmpty()) { - node = nodeList.head(); - nodeList = nodeList.tail(); - return true; - } - - for (;treeMapIterator.hasNext();) { - nodeList = treeMapIterator.next()._2(); - node = nodeList.head(); - nodeList = nodeList.tail(); + if (treeMapIterator.hasNext()) { + node = treeMapIterator.next(); return true; } return false; @@ -132,13 +110,13 @@ public TreeNode next() { return node; } - + }; - + } - + public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { return indexList; } - + }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/ParentIndex.java Wed Dec 24 15:05:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/ParentIndex.java Wed Dec 24 16:14:42 2014 +0900 @@ -1,21 +1,18 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; import java.util.Iterator; +import java.util.TreeMap; 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.Ord; -import fj.data.Option; -import fj.data.TreeMap; + public class ParentIndex { private TreeMap<TreeNode, TreeNode> parentIndex; public ParentIndex() { - Ord<TreeNode> aaa = TreeMapOrd.treeNodeOrd; - parentIndex = TreeMap.empty(aaa); + parentIndex = new TreeMap<TreeNode,TreeNode>(); } public ParentIndex(TreeMap<TreeNode, TreeNode> parentIndex) { @@ -35,23 +32,21 @@ } public TreeNode get(TreeNode child) { - Option<TreeNode> parentOp = parentIndex.get(child); - if (parentOp.isSome()) - return parentOp.some(); - return null; + TreeNode parentNode = parentIndex.get(child); + return parentNode; } public ParentIndex set(TreeNode parent) { Iterator<TreeNode> childrenIterator = parent.getChildren().iterator(); for (; childrenIterator.hasNext();) { TreeNode child = childrenIterator.next(); - parentIndex = parentIndex.set(child, parent); + parentIndex.put(child, parent); } return this; } public ParentIndex delete(TreeNode child) { - parentIndex = parentIndex.delete(child); + parentIndex.remove(child); return this; } @@ -60,7 +55,7 @@ Iterator<TreeNode> childrenIterator = children.iterator(); for (; childrenIterator.hasNext();) { TreeNode child = childrenIterator.next(); - parentIndex = parentIndex.delete(child); + parentIndex.remove(child); } return this; } @@ -70,7 +65,7 @@ Iterator<TreeNode> childrenIterator = children.iterator(); for (; childrenIterator.hasNext();) { TreeNode child = childrenIterator.next(); - parentIndex = parentIndex.set(child, parentNode); + parentIndex.put(child, parentNode); } return this; }