(1) -spec from_list(List) -> Orddict when | (2) List:: [Key:: term(), Value:: term()], | (3) Orddict:: orddict(). | (4) | (5) from_list(Pairs) -> | (6) lists:foldl( | (7) fun (K,V, D) -> store(K, V, D) end, [], Pairs). | (8) | (9) -spec store(Key, Value, Orddict1) -> Orddict2 when | (10) Key:: term(), | (11) Value:: term(), | (12) Orddict1:: orddict(), | (13) Orddict2:: orddict(). | (14) | (15) store(Key, New, [K,_=E∣Dict]) when Key < K -> | (16) [Key,New,E∣Dict]; | (17) store(Key, New, [K,_=E∣Dict]) when Key > K -> | (18) [E∣store(Key, New, Dict)]; | (19) store(Key, New, [_K,_Old∣Dict]) -> % Key == K | (20) [Key,New∣Dict]; | (21) store(Key, New, []) -> [Key,New]. |
|