Mercurial > hg > Members > tatsuki > functionaljava-master > core
changeset 2:d2b4440b2cc0
change getLoop
author | tatsuki |
---|---|
date | Sat, 21 Mar 2015 08:06:30 +0900 |
parents | 8ed7d71e8617 |
children | 68e5def4e745 |
files | src/main/java/fj/Ord.java src/main/java/fj/data/TreeMap.java |
diffstat | 2 files changed, 24 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/fj/Ord.java Sat Mar 21 05:32:16 2015 +0900 +++ b/src/main/java/fj/Ord.java Sat Mar 21 08:06:30 2015 +0900 @@ -363,7 +363,8 @@ public F<String, Ordering> f(final String a1) { return new F<String, Ordering>() { public Ordering f(final String a2) { - final int x = a1.compareTo(a2); + //final int x = a1.compareTo(a2); + final int x = a1.hashCode() - a2.hashCode(); return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; } };
--- a/src/main/java/fj/data/TreeMap.java Sat Mar 21 05:32:16 2015 +0900 +++ b/src/main/java/fj/data/TreeMap.java Sat Mar 21 08:06:30 2015 +0900 @@ -32,6 +32,7 @@ * @return an empty TreeMap with the given key order. */ public static <K, V> TreeMap<K, V> empty(final Ord<K> keyOrd) { + System.out.println("4"); return new TreeMap<K, V>(Set.empty(TreeMap.<K, V>ord(keyOrd))); } @@ -41,7 +42,7 @@ * @param k The key to look up in the tree map. * @return A potential value for the given key. */ - public Option<V> get(final K k) { + public Option<V> get(final K k) { // Option<V> op = Option.<V> none(); // Option<P2<K, Option<V>>> attribute = tree.mapGet(P.p(k, op)); // return attribute.bind(P2.<K, Option<V>> __2()); @@ -51,29 +52,31 @@ // // // // System.out.println("aaaa"); // // return x.bind(P2.<K, Option<V>>__2()); - return null; - } + return getLoop(k); + } + public Option<V> getLoop(final K k) { Set<P2<K, V>> cur = tree; - Option<V> op = Option.<V>none(); - +// Option<V> op = Option.<V>none(); while (!cur.isEmpty()) { - Ord<P2<K, V>> ttt = cur.ord(); -// P2<K, V> head = cur.head(); - K h = cur.head()._1_()._1(); - int i = h.hashCode() - k.hashCode(); - // Ord<P2<K, V>> ord = cur.ord(); - // Ordering i = ord.compare(P.p(k,null), cur.head()); +// Ord<P2<K, V>> ttt = cur.ord(); + + P2<K, V> head = cur.head(); + K h = head._1(); + final int i = h.hashCode() - k.hashCode(); + // Ord<P2<K, V>> ord = cur.ord(); + // Ordering i = ord.compare(P.p(k,null), cur.head()); if (i > 0) cur = cur.l(); else if (i < 0) cur = cur.r(); else - return Option.<V>some(cur.head()._2()); + return Option.<V>some(head._2()); } return Option.<V>none(); + // return Option.<V>none(); } /** @@ -209,19 +212,18 @@ * Modifies the value for the given key, if present, by applying the given * function to it. * - * @param k - * The key for the value to modify. - * @param f - * A function with which to modify the value. + * @param k The key for the value to modify. + * @param f A function with which to modify the value. * @return A new tree map with the value for the given key transformed by the - * given function, paired with True if the map was modified, otherwise - * False. + * given function, paired with True if the map was modified, otherwise + * False. */ -// public P2<Boolean, TreeMap<K, V>> update(final K k, final F<V, V> f) { + public P2<Boolean, TreeMap<K, V>> update(final K k, final F<V, V> f) { + return null; // final P2<Boolean, Set<P2<K, Option<V>>>> up = tree.update(p(k, Option.<V> none()), // P2.<K, Option<V>, Option<V>> map2_(Option.<V, V> map().f(f))); // return P.p(up._1(), new TreeMap<K, V>(up._2())); -// } + } /** * Modifies the value for the given key, if present, by applying the given