CompressedList

Unrolled list

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

back
T back()

List back item.

clear
void clear()

remove anything from list

empty
bool empty()

Is list empty?

front
T front()

List front item

insertBack
NodePointer insertBack(T v)

Insert item back.

insertFront
NodePointer insertFront(T v)

Insert item at front.

length
ulong length()

Items in the list.

popBack
void popBack()

Pop back item from list.

popFront
void popFront()

Pop front item

range
Range range()

Iterator over items.

remove
void remove(ref NodePointer p)

remove node (by 'Pointer')

Structs

NodePointer
struct NodePointer
Page
struct Page

unrolled list with support only for: 1. insert/delete front 2. insert/delete back 3. keep unstable "pointer" to arbitrary element 4. remove element by pointer

Examples

1 import std.experimental.logger;
2 import std.algorithm;
3 import std.range;
4 
5 globalLogLevel = LogLevel.info;
6 CompressedList!int list;
7 foreach(i;0..66)
8 {
9     list.insertFront(i);
10     assert(list.front == i);
11 }
12 assert(list.length == 66);
13 assert(list.back == 0);
14 list.popFront();
15 assert(list.length == 65);
16 assert(list.front == 64);
17 list.popFront();
18 assert(list.length == 64);
19 assert(list.front == 63);
20 while( !list.empty )
21 {
22     list.popFront();
23 }
24 foreach(i;1..19)
25 {
26     list.insertFront(i);
27     assert(list.front == i);
28 }
29 foreach(i;1..19)
30 {
31     assert(list.back == i);
32     assert(list.length == 19-i);
33     list.popBack();
34 }
35 assert(list.empty);
36 auto p99 = list.insertBack(99);
37 assert(list.front == 99);
38 assert(list.back == 99);
39 auto p100 = list.insertBack(100);
40 assert(list.front == 99);
41 assert(list.back == 100);
42 auto p98 = list.insertFront(98);
43 auto p101 = list.insertBack(101);
44 () @trusted // * and remove for poiners is unsafe
45 {
46     assert(*p98 == 98);
47     assert(list.length == 4);
48     list.remove(p98);
49     assert(list.length == 3);
50     assert(list.front == 99);
51     list.remove(p100);
52     assert(list.length == 2);
53     assert(list.front == 99);
54     assert(list.back == 101);
55     list.remove(p99);
56     assert(list.length == 1);
57     list.clear();
58 
59     foreach(i;0..1000)
60     {
61         list.insertBack(i);
62     }
63     assert(equal(list.range(), iota(0,1000)));
64     list.clear();
65 
66     iota(0, 1000).
67         map!(i => list.insertBack(i)).
68         array.
69         each!(p => list.remove(p));
70     assert(list.empty);
71     iota(0, 1000).map!(i => list.insertBack(i));
72     auto r = list.range();
73     while(!r.empty)
74     {
75         int v = r.front;
76         r.popFront();
77     }
78     assert(list.empty);
79 }();
80 
81 () @nogc
82 {
83     struct S {}
84     CompressedList!(immutable S) islist;
85     immutable S s = S();
86     islist.insertFront(s);
87 }();
88 class C
89 {
90     int c;
91     this(int v) {
92         c = v;
93     }
94 }
95 CompressedList!C clist;
96 foreach(i;0..5000)
97 {
98     clist.insertBack(new C(i));
99 }
100 foreach(i;0..4500)
101 {
102     clist.popBack();
103 }
104 assert(clist.length == 500);
105 clist.clear();

Meta