forked from robertovrf/self_distributing_systems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList.dn
67 lines (56 loc) · 2.52 KB
/
List.dn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
{"description" : "An ordered list of items."}
*/
interface List {
/* {"@description" : "The contents of the list."} */
transfer Data content[]
/* {"@description" : "The current iterator index."} */
transfer int iteratorIndex
/*
{"@description" : "Add a new item to the list; this function adds a reference (shallow copy) of the given item onto the list."}
*/
void add (store Data item)
/*
{"@description" : "Remove an item from the list; this function locates the given item using a reference (===) check."}
*/
void remove (Data item)
/*
{"@description" : "Update an existing list item to a new version. This locates the given item using a reference (===) check, then replaces that reference with the reference to newVersion."}
*/
void update (Data item , store Data newVersion)
/*
{"@description" : "Iterator: call this function to begin iterating over the list. Note that this function, together with getNext(), are not thread-safe: if getFirst() is called by thread A, which then begins using getNext() to iterate through the list, a second call of getFirst() by thread B will reset thread A's iterator.",
"@return" : "The first element in the list, or null if the list is empty."}
*/
Data getFirst ()
/*
{"@description" : "Iterator: call this function to get the next element in the list.",
"@return" : "The next element in the list, or null if the end of the list has been reached."}
*/
Data getNext ()
/*
{"@description" : "Iterator: call this function to check if we've reached the end of the list, such that calling getNext() again would return null as there are no more items.",
"@return" : "True if the end of the list has been reached; false otherwise."}
*/
bool isEnd ()
/*
{"@description" : "Get the data instance at this index in the list.",
"@return" : "The data instance at this index, if any, or null if the index is out of bounds or empty."}
*/
Data getIndex (int n)
/*
{"@description" : "Set the given index of the list to stored the given data instance."}
*/
void setIndex (int n, store Data d)
/*
{"@description" : "Get the number of items currently stored in the list.",
"@return" : "The number of items in the list."}
*/
int getLength ()
/*
{"@description" : "Get all items in the list as an array of type Data[].",
"t" : "The specific type for the resulting array.",
"@return" : "An array of type Data[] containing all items in the list, in order."}
*/
Data[] getContents (opt Type t)
}