Mercurial > projects > dynamin
comparison dynamin/core/list.d @ 80:f1e176a76c00
Rearrange List constructors and add a constant for the default capacity.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 17 Jul 2010 16:51:03 -0500 |
parents | c2566ab82535 |
children | de94552446ab |
comparison
equal
deleted
inserted
replaced
79:e7595d58f8a3 | 80:f1e176a76c00 |
---|---|
43 uint _count; | 43 uint _count; |
44 static if(hasDelegates) { | 44 static if(hasDelegates) { |
45 void delegate(T, int) whenAdded; | 45 void delegate(T, int) whenAdded; |
46 void delegate(T, int) whenRemoved; | 46 void delegate(T, int) whenRemoved; |
47 } | 47 } |
48 const int DefaultCapacity = 16; | |
48 public: | 49 public: |
49 this() { | |
50 this(16); | |
51 } | |
52 this(uint capacity) { | |
53 _data = new T[capacity]; | |
54 } | |
55 static if(hasDelegates) { | 50 static if(hasDelegates) { |
56 /// whenAdded or whenRemoved is called right after an item is added | 51 /// whenAdded or whenRemoved is called right after an item is added |
57 /// or removed | 52 /// or removed |
58 this(void delegate(T, int) whenAdded, | 53 this(void delegate(T, int) whenAdded, |
59 void delegate(T, int) whenRemoved) { | 54 void delegate(T, int) whenRemoved) { |
60 this(16, whenAdded, whenRemoved); | 55 this(DefaultCapacity, whenAdded, whenRemoved); |
61 } | 56 } |
62 this(uint capacity, void delegate(T, int) whenAdded, | 57 this(uint capacity, |
63 void delegate(T, int) whenRemoved) { | 58 void delegate(T, int) whenAdded, |
64 this(capacity); | 59 void delegate(T, int) whenRemoved) { |
60 _data = new T[capacity]; | |
65 this.whenAdded = whenAdded; | 61 this.whenAdded = whenAdded; |
66 this.whenRemoved = whenRemoved; | 62 this.whenRemoved = whenRemoved; |
63 } | |
64 } else { | |
65 this() { | |
66 this(DefaultCapacity); | |
67 } | |
68 this(uint capacity) { | |
69 _data = new T[capacity]; | |
67 } | 70 } |
68 } | 71 } |
69 static List!(T) fromArray(T[] arr...) { | 72 static List!(T) fromArray(T[] arr...) { |
70 auto list = new List!(T)(); | 73 auto list = new List!(T)(); |
71 list._data = arr.dup; | 74 list._data = arr.dup; |