Created
June 23, 2020 21:06
-
-
Save korchoon/34953075fe37c9b19d3724ffb3b04bc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GrowList<T> { | |
public T[] Items; | |
public int Count; | |
public GrowList (int capacity) { | |
Items = new T[capacity]; | |
Count = 0; | |
} | |
public void Add (T item) { | |
if (Items.Length == Count) { | |
Array.Resize (ref Items, Items.Length << 1); | |
} | |
Items[Count++] = item; | |
} | |
public void EnsureCapacity (int count) { | |
if (Items.Length < count) { | |
var len = Items.Length << 1; | |
while (len <= count) { | |
len <<= 1; | |
} | |
Array.Resize (ref Items, len); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment