Skip to content

Commit d0dc441

Browse files
committed
Merged github issue functionaljava#13
1 parent 899f779 commit d0dc441

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

core/src/main/java/fj/data/TreeMap.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ public Option<V> get(final K k) {
6060
* @return A new tree map with the given value mapped to the given key.
6161
*/
6262
public TreeMap<K, V> set(final K k, final V v) {
63-
final P3<Set<P2<K, Option<V>>>, Option<P2<K, Option<V>>>, Set<P2<K, Option<V>>>> x
64-
= tree.split(P.p(k, Option.<V>none()));
65-
return new TreeMap<K, V>(x._1().union(x._3().insert(P.p(k, Option.some(v)))));
63+
return new TreeMap<K, V>(tree.insert(P.p(k, Option.some(v))));
6664
}
6765

6866
/**
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package fj.data;
2+
3+
import fj.Ord;
4+
import fj.P2;
5+
import org.junit.Test;
6+
7+
import java.util.ArrayList;
8+
9+
/**
10+
* Created by MarkPerry on 2/06/2014.
11+
*/
12+
public class TestTreeMap {
13+
14+
@Test
15+
public void testLargeInserts() {
16+
// check that inserting a large number of items performs ok
17+
// taken from https://code.google.com/p/functionaljava/issues/detail?id=31 and
18+
// https://github.com/functionaljava/functionaljava/pull/13/files
19+
final int n = 10000;
20+
TreeMap<Integer, String> m = TreeMap.empty(Ord.intOrd);
21+
for (int i = 0; i < n; i++) {
22+
m = m.set(i, "abc " + i);
23+
}
24+
}
25+
26+
}

0 commit comments

Comments
 (0)