constructor
appends an element to the list
appends an array to the list
empties the list
removes the free space, if any, for adding new elements. Call this when done with adding to list.
Inserts an array into this list
Inserts an element into this list
Loads list from an array
Reads an element at index=seek. Seek is increased by one
Reads a number of elements starting at index=seek. Seek is increased by number of elements
Reads an element at an index
Read a slice from the list.
Reads the last element in list.
Reads number of elements from end of list
Removes last elements(s) starting from an index
Removes number of elements from end of list
Writes the list to a file.
Changes the value of element at an index.
make more free space for new elements, or reduce it. To reduce, use n as negative. To decrease by 2, n=-2
shrinks the size of the list, removing last elements.
Exports this list into a array
Changes the value of element at seek. Seek is increased by one
Changes the value of elements starting at index=seek. Seek is increased by number of elements affected
The seek position
1 List!ubyte list = new List!ubyte(4); 2 //`List.insert` and `List.add` and `List.toArray` 3 list.append(0); 4 list.append(1); 5 list.insert(1, 2); 6 assert(list.toArray() == [0, 2, 1]); 7 //`List.indexOf` 8 assert(list.indexOf(1) == 2); 9 //`List.clear` 10 list.clear; 11 assert(list.length == 0); 12 //`List.loadArray` 13 list.loadArray([0, 1, 2, 3]); 14 assert(list.length == 4); 15 assert(list.indexOf(3) == 3); 16 //`List.addArray` 17 list.append([4, 5, 6, 7, 8]); 18 assert(list.length == 9); 19 //`List.set` and `List.read` 20 list.set(0, 1); 21 assert(list.read(0) == 1); 22 //`List.readLast` 23 assert(list.readLast() == 8); 24 assert(list.readLast(2) == [7, 8]); 25 //`List.readRange` 26 assert(list.read(0, 2) == [1, 1]); 27 //`List.remove` 28 list.remove(0, 2); 29 assert(list.read(0) == 2); 30 //`List.removeLast` 31 list.removeLast(2); 32 assert(list.readLast() == 6); 33 //`List.freeSpace` 34 list.clear; 35 foreach (i; cast(ubyte[])[0,1,2]) 36 list.append(i); 37 assert(list.freeSpace == 1, to!string(list.freeSpace)); 38 list.append(3); 39 assert(list.freeSpace == 0); 40 list.setFreeSpace(6); 41 assert(list.freeSpace == 6 && list.length == 4); 42 list.setFreeSpace(-3); 43 assert(list.freeSpace == 3); 44 assert(list.setFreeSpace(-10) == false); 45 //reading/writing with seek 46 list.clear; 47 assert(list.seek == 0); 48 list.append([0,1,2,3,4,5,6,7,8]); 49 assert(list.seek == 0); 50 ubyte[] buffer; 51 buffer.length = 4; 52 assert(list.read(buffer) == 4); 53 assert(buffer == [0,1,2,3]); 54 assert(list.seek == 4); 55 assert(list.read == 4); 56 assert(list.write(5) == true); 57 assert(list.read(buffer) == 3); 58 assert(buffer[0 .. 3] == [6,7,8]); 59 assert(list.seek == 9); 60 //`List.readPtr` 61 list.clear; 62 list.append ([0,1,2,3,4,5]); 63 ubyte* ptr = list.readPtr(5); 64 *ptr = 4; 65 assert (list.toArray == [0,1,2,3,4,4]); 66 67 destroy(list);
Use to manage dynamic arrays that frequently change lengths
Provides more functionality for arrays, like searching in arrays, removing elements...