|
23 | 23 | */ |
24 | 24 |
|
25 | 25 | @SuppressWarnings("unchecked") |
26 | | -public class SortedSet extends ASortedSet implements IEditableCollection, ITransientCollection, Reversible, Sorted, IReduce { |
| 26 | +public class SortedSet extends ASortedSet implements IEditableCollection, ITransientSet, Reversible, Sorted, IReduce, ISortedSet { |
27 | 27 |
|
28 | 28 | static Leaf[] EARLY_EXIT = new Leaf[0], |
29 | 29 | UNCHANGED = new Leaf[0]; |
30 | 30 |
|
31 | 31 | static int MIN_LEN = 32, MAX_LEN = 64, EXTRA_LEN = 8; |
32 | 32 |
|
| 33 | + public static final SortedSet EMPTY = new SortedSet(); |
| 34 | + |
33 | 35 | static class Edit { |
34 | 36 | public volatile boolean _value = false; |
35 | 37 | Edit(boolean value) { _value = value; } |
@@ -62,6 +64,7 @@ public SortedSet(IPersistentMap meta, Comparator cmp) { |
62 | 64 | _edit = edit; |
63 | 65 | } |
64 | 66 |
|
| 67 | + // ISortedSet |
65 | 68 | public Seq slice(Object from, Object to) { return slice(from, to, _cmp); } |
66 | 69 | public Seq slice(Object from, Object to, Comparator cmp) { |
67 | 70 | assert from == null || to == null || cmp.compare(from, to) <= 0 : "From " + from + " after to " + to; |
@@ -158,27 +161,19 @@ public SortedSet withMeta(IPersistentMap meta) { |
158 | 161 | // Counted |
159 | 162 | public int count() { return _count; } |
160 | 163 |
|
161 | | - // Seqable |
162 | | - public Seq seq() { return slice(null, null, _cmp); } |
163 | | - |
164 | | - // Reversible |
165 | | - public ISeq rseq() { return rslice(null, null, _cmp); } |
166 | | - |
167 | 164 | // Sorted |
168 | 165 | public Comparator comparator() { return _cmp; } |
169 | 166 | public Object entryKey(Object entry) { return entry; } |
170 | | - public ISeq seq(boolean asc) { return asc ? seq() : rseq(); } |
171 | | - public ISeq seqFrom(Object key, boolean asc) { return asc ? slice(key, null) : rslice(key, null); } |
172 | 167 |
|
173 | 168 | // IReduce |
174 | 169 | public Object reduce(IFn f) { |
175 | | - Seq seq = seq(); |
| 170 | + Seq seq = (Seq) seq(); |
176 | 171 | return seq == null ? f.invoke() : seq.reduce(f); |
177 | 172 | } |
178 | 173 |
|
179 | 174 | public Object reduce(IFn f, Object start) { |
180 | | - Seq seq = seq(); |
181 | | - return seq == null ? start : seq().reduce(f, start); |
| 175 | + Seq seq = (Seq) seq(); |
| 176 | + return seq == null ? start : seq.reduce(f, start); |
182 | 177 | } |
183 | 178 |
|
184 | 179 | // IPersistentCollection |
@@ -263,7 +258,7 @@ public SortedSet persistent() { |
263 | 258 |
|
264 | 259 | // Iterable |
265 | 260 | public Iterator iterator() { |
266 | | - return new JavaIter(seq()); |
| 261 | + return new JavaIter((Seq) seq()); |
267 | 262 | } |
268 | 263 |
|
269 | 264 |
|
|
0 commit comments