# HG changeset patch # User tatsuki # Date 1426892790 -32400 # Node ID d2b4440b2cc0f88728d377e4122a1f6ee07d9ea6 # Parent 8ed7d71e861726bc1dec2c7897a55917d84f3a94 change getLoop diff -r 8ed7d71e8617 -r d2b4440b2cc0 src/main/java/fj/Ord.java --- 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 f(final String a1) { return new F() { 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; } }; diff -r 8ed7d71e8617 -r d2b4440b2cc0 src/main/java/fj/data/TreeMap.java --- 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 TreeMap empty(final Ord keyOrd) { + System.out.println("4"); return new TreeMap(Set.empty(TreeMap.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 get(final K k) { + public Option get(final K k) { // Option op = Option. none(); // Option>> attribute = tree.mapGet(P.p(k, op)); // return attribute.bind(P2.> __2()); @@ -51,29 +52,31 @@ // // // // System.out.println("aaaa"); // // return x.bind(P2.>__2()); - return null; - } + return getLoop(k); + } + public Option getLoop(final K k) { Set> cur = tree; - Option op = Option.none(); - +// Option op = Option.none(); while (!cur.isEmpty()) { - Ord> ttt = cur.ord(); -// P2 head = cur.head(); - K h = cur.head()._1_()._1(); - int i = h.hashCode() - k.hashCode(); - // Ord> ord = cur.ord(); - // Ordering i = ord.compare(P.p(k,null), cur.head()); +// Ord> ttt = cur.ord(); + + P2 head = cur.head(); + K h = head._1(); + final int i = h.hashCode() - k.hashCode(); + // Ord> 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.some(cur.head()._2()); + return Option.some(head._2()); } return Option.none(); + // return Option.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> update(final K k, final F f) { + public P2> update(final K k, final F f) { + return null; // final P2>>> up = tree.update(p(k, Option. none()), // P2., Option> map2_(Option. map().f(f))); // return P.p(up._1(), new TreeMap(up._2())); -// } + } /** * Modifies the value for the given key, if present, by applying the given