Mercurial > hg > Members > tatsuki > bench > jungle-core
diff src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java @ 153:20af7f25ef32
miner change
author | one |
---|---|
date | Tue, 25 Nov 2014 17:52:41 +0900 |
parents | d9fbddf77bf6 |
children | c23f70bb791f 89ed172137ab |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java Sat Nov 22 15:25:09 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/Index.java Tue Nov 25 17:52:41 2014 +0900 @@ -2,6 +2,7 @@ import java.util.Iterator; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NulIterator; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import fj.Ord; import fj.P2; @@ -27,8 +28,16 @@ public Index set(String key, String value, TreeNode node) { Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); - if (indexOp.isNone()) - return this; + 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<String, List<TreeNode>>> newIndexList = indexList.set(key, newIndex); + + + return new Index(newIndexList); + } TreeMap<String, List<TreeNode>> index = indexOp.some(); Option<List<TreeNode>> nodeListOp = index.get(value); @@ -43,101 +52,42 @@ } TreeMap<String, List<TreeNode>> newIndex = index.set(value, newNodeList); 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 Index deleteNodeAll(TreeNode node) { - List<String> keys = node.getAttributes().getKeys(); - TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexList = indexList; - - for (String key : keys) { - Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); - if (indexOp.isNone()) - continue; - - TreeMap<String, List<TreeNode>> index = indexOp.some(); - Iterator<P2<String, List<TreeNode>>> indexIterator = index.iterator(); - - TreeMap<String, List<TreeNode>> newIndex = index; - for (; indexIterator.hasNext();) { - List<TreeNode> newNodeList = List.nil(); - P2<String, List<TreeNode>> NodeListP2 = indexIterator.next(); - String value = NodeListP2._1(); - List<TreeNode> targetNodeList = NodeListP2._2(); - for (TreeNode targetNode : targetNodeList) { - if (!node.equals(targetNode)) - newNodeList = newNodeList.cons(targetNode); - } - newIndex = newIndex.set(value, newNodeList); - } - 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 Index putNodeAll(TreeNode node) { - List<String> keys = node.getAttributes().getKeys(); - TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexList = indexList; - - for (String key : keys) { - - String value = node.getAttributes().getString(key); - if (value == null) - continue; - - Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); - if (indexOp.isNone()) - continue; - TreeMap<String, List<TreeNode>> index = indexOp.some(); - Option<List<TreeNode>> nodeListOp = index.get(value); - TreeMap<String, List<TreeNode>> newIndex = index; - - if (nodeListOp.isNone()) { - List<TreeNode> newNodeList = List.nil(); - newNodeList = newNodeList.cons(node); - newIndex = newIndex.set(value, newNodeList); - } else { - List<TreeNode> newNodeList = nodeListOp.some(); - newNodeList = newNodeList.cons(node); - newIndex = newIndex.set(value, newNodeList); - } - - newIndexList = newIndexList.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()) - return List.nil(); + return null; TreeMap<String, List<TreeNode>> index = indexOp.some(); Option<List<TreeNode>> nodeListOp = index.get(value); @@ -148,6 +98,49 @@ return nodeListOp.some(); } + public Iterator<TreeNode> getAll(String key){ + + Option<TreeMap<String, List<TreeNode>>> indexOp = indexList.get(key); + if (indexOp.isNone()) + return null; + + 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(); + 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(); + return true; + } + return false; + } + + @Override + public TreeNode next() { + return node; + } + + }; + + } private TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { return indexList;