Immutable Collections (3) Immutable List ()
/Xuan Hun
Immutable Collections(2)ImmutableList <T>Implementation Principle.(I), ImmutableList <T>
. NET
3.1 ADD
Main ([] args) {fruitBasket =. Create <> (); ass = fruitBasket. Add ();}
<T>. Add (T key) {. Insert (. count, key );}
(. IsEmpty) // {<T>. (key ,,,);}
Node (T key, <T>. left, <T>. right, frozen = ){. notNull <T>.> (left ,);. notNull <T>.> (right ,);. key = key ;. left = left ;. right = right ;. height = 1 +. max (left. height, right. height );. count = 1 + left. count + right. count ;. frozen = frozen ;}
Frozen = falseNode (T key, ImmutableList <T>. Node left, ImmutableList <T>. Node right, bool frozen = false) thisthis
NodeNewNode
<T> Add (T value) {<T>. node =. root. Add (value);. Wrap (node );}
ImmutableList (<T>. root, <T> valueComparer ){. notNull <T>.> (root ,);. notNull <T> (valueComparer,); root. freeze ();. root = root ;. valueComparer = valueComparer ;}
Main ([] args) {fruitBasket =. Create <> (); a2 = fruitBasket. Add (); a3 = a2.Add ();}