MCPcopy Index your code
hub / github.com/clojure/clojure / PersistentTreeMap

Class PersistentTreeMap

src/jvm/clojure/lang/PersistentTreeMap.java:26–1056  ·  view source on GitHub ↗

Persistent Red Black Tree Note that instances of this class are constant values i.e. add/remove etc return new values See Okasaki, Kahrs, Larsen et al

Source from the content-addressed store, hash-verified

24 */
25
26public class PersistentTreeMap extends APersistentMap implements IObj, Reversible, Sorted, IKVReduce{
27
28public final Comparator comp;
29public final Node tree;
30public final int _count;
31final IPersistentMap _meta;
32
33final static public PersistentTreeMap EMPTY = new PersistentTreeMap();
34
35static public IPersistentMap create(Map other){
36 IPersistentMap ret = EMPTY;
37 for(Object o : other.entrySet())
38 {
39 Map.Entry e = (Entry) o;
40 ret = ret.assoc(e.getKey(), e.getValue());
41 }
42 return ret;
43}
44
45public PersistentTreeMap(){
46 this(RT.DEFAULT_COMPARATOR);
47}
48
49public PersistentTreeMap withMeta(IPersistentMap meta){
50 if(_meta == meta)
51 return this;
52 return new PersistentTreeMap(meta, comp, tree, _count);
53}
54
55private PersistentTreeMap(Comparator comp){
56 this(null, comp);
57}
58
59
60public PersistentTreeMap(IPersistentMap meta, Comparator comp){
61 this.comp = comp;
62 this._meta = meta;
63 tree = null;
64 _count = 0;
65}
66
67PersistentTreeMap(IPersistentMap meta, Comparator comp, Node tree, int _count){
68 this._meta = meta;
69 this.comp = comp;
70 this.tree = tree;
71 this._count = _count;
72}
73
74static public PersistentTreeMap create(ISeq items){
75 IPersistentMap ret = EMPTY;
76 for(; items != null; items = items.next().next())
77 {
78 if(items.next() == null)
79 throw new IllegalArgumentException(String.format("No value supplied for key: %s", items.first()));
80 ret = ret.assoc(items.first(), RT.second(items));
81 }
82 return (PersistentTreeMap) ret;
83}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected