comparison src/main/java/fj/data/TreeMap.java @ 4:19c719aba746 default tip

change getLoop return value
author tatsuki
date Mon, 20 Apr 2015 08:09:22 +0900
parents 68e5def4e745
children
comparison
equal deleted inserted replaced
3:68e5def4e745 4:19c719aba746
30 * 30 *
31 * @param keyOrd An order for the keys of the tree map. 31 * @param keyOrd An order for the keys of the tree map.
32 * @return an empty TreeMap with the given key order. 32 * @return an empty TreeMap with the given key order.
33 */ 33 */
34 public static <K, V> TreeMap<K, V> empty(final Ord<K> keyOrd) { 34 public static <K, V> TreeMap<K, V> empty(final Ord<K> keyOrd) {
35 System.out.println("4");
36 return new TreeMap<K, V>(Set.empty(TreeMap.<K, V>ord(keyOrd))); 35 return new TreeMap<K, V>(Set.empty(TreeMap.<K, V>ord(keyOrd)));
37 } 36 }
38 37
39 /** 38 /**
40 * Returns a potential value that the given key maps to. 39 * Returns a potential value that the given key maps to.
50 // // Option<V>>>> splitTree = tree.split(P.p(k, op)); 49 // // Option<V>>>> splitTree = tree.split(P.p(k, op));
51 // // final Option<P2<K, Option<V>>> x = splitTree._2(); 50 // // final Option<P2<K, Option<V>>> x = splitTree._2();
52 // // 51 // //
53 // // System.out.println("aaaa"); 52 // // System.out.println("aaaa");
54 // // return x.bind(P2.<K, Option<V>>__2()); 53 // // return x.bind(P2.<K, Option<V>>__2());
55 return getLoop(k); 54 return Option.<V>some(getLoop(k));
56 } 55 }
57 56
58 public Option<V> getLoop(final K k) { 57 public V getLoop(final K k) {
59 Set<P2<K, V>> cur = tree; 58 Set<P2<K, V>> cur = tree;
60 // Option<V> op = Option.<V>none(); 59 // Option<V> op = Option.<V>none();
61 while (!cur.isEmpty()) { 60 while (!cur.isEmpty()) {
62 // Ord<P2<K, V>> ttt = cur.ord(); 61 // Ord<P2<K, V>> ttt = cur.ord();
63 62
69 if (i > 0) 68 if (i > 0)
70 cur = cur.l(); 69 cur = cur.l();
71 else if (i < 0) 70 else if (i < 0)
72 cur = cur.r(); 71 cur = cur.r();
73 else 72 else
74 return Option.<V>some(head._2()); 73 return head._2();
75 74
76 75
77 } 76 }
78 return Option.<V>none(); 77 return null;
79 // return Option.<V>none(); 78 // return Option.<V>none();
80 } 79 }
81 80
82 /** 81 /**
83 * Inserts the given key and value association into the tree map. If the given 82 * Inserts the given key and value association into the tree map. If the given
201 * @return a functional representation of this TreeMap. 200 * @return a functional representation of this TreeMap.
202 */ 201 */
203 public F<K, Option<V>> get() { 202 public F<K, Option<V>> get() {
204 return new F<K, Option<V>>() { 203 return new F<K, Option<V>>() {
205 public Option<V> f(final K k) { 204 public Option<V> f(final K k) {
206 return getLoop(k); 205 return get(k);
207 } 206 }
208 }; 207 };
209 } 208 }
210 209
211 /** 210 /**