The OpenD Programming Language

CompressedList

unrolled list with support only for: 1. insert/delete front O(1) 2. insert/delete back O(1) 3. access/remove by index O(n/m), m - nodes per page

version(!unittest)
deprecated
struct CompressedList (
T
Allocator = Mallocator
bool GCRangesAllowed = true
) {
enum PageSize;
enum NodesPerPage;
enum BitMapLength;
}

Destructor

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

Postblit

A postblit 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
void insertBack(T v)

Insert item back.

insertFront
void 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.

Structs

Page
struct Page
Undocumented in source.

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 list.insertBack(99);
37 assert(list.front == 99);
38 assert(list.back == 99);
39 list.insertBack(100);
40 assert(list.front == 99);
41 assert(list.back == 100);
42 list.insertFront(98);
43 list.insertBack(101);
44 () @trusted // * and remove for poiners is unsafe
45 {
46     list.clear();
47     assert(list.empty);
48 
49     foreach(i;0..1000)
50     {
51         list.insertBack(i);
52     }
53     assert(equal(list.range(), iota(0,1000)));
54     list.clear();
55 
56     assert(list.empty);
57     iota(0, 1000).each!(i => list.insertBack(i));
58     auto r = list.range();
59     while(!r.empty)
60     {
61         int v = r.front;
62         r.popFront();
63     }
64     assert(list.length == 1000, "expected empty list, got length %d".format(list.length));
65 }();
66 
67 () @nogc
68 {
69     struct S {}
70     CompressedList!(immutable S) islist;
71     immutable S s = S();
72     islist.insertFront(s);
73 }();
74 class C
75 {
76     int c;
77     this(int v) {
78         c = v;
79     }
80 }
81 CompressedList!C clist;
82 foreach(i;0..5000)
83 {
84     clist.insertBack(new C(i));
85 }
86 foreach(i;0..4500)
87 {
88     clist.popBack();
89 }
90 assert(clist.length == 500);
91 clist.clear();

Meta