-
Notifications
You must be signed in to change notification settings - Fork 2
/
Collections.kc
87 lines (76 loc) · 2 KB
/
Collections.kc
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/** This module provides the interface to the KOS collections.
* A major difference is that all collections are now parameterized over the type of elements they contain.
*/
module KOS::Collections;
import KOS::Builtin unqualified;
builtin structure Iterator<A> : Structure {
Void Reset();
Boolean Next();
Boolean AtEnd;
Scalar Index get;
A Value get;
}
// This type is required for type checking for-each statements.
builtin structure Enumerable<A> : Structure {
Iterator<A> Iterator get;
Iterator<A> ReverseIterator get;
Scalar Length get;
Boolean Contains(A item);
Boolean Empty get;
String Dump();
}
builtin structure List<A> : Enumerable<A> {
A [Scalar index];
Void Add(A item);
Void Insert(Scalar index, A item);
Void Remove(Scalar index);
Void Clear();
List<A> Copy();
List<A> SubList(Scalar index, Scalar length);
String Join(String separator);
}
// TODO: implement varargs for this function in order to construct lists
/// can only construct the empty list currently
builtin List<A> List<A>();
builtin structure Lexicon<K, V> : Structure {
V [K key];
Void Add(K key, V value);
Boolean CaseSensitive;
Boolean Case;
Void Clear();
Lexicon<K, V> Copy();
String Dump();
Boolean HasKey(K key);
Boolean HasValue(V value);
List<K> Keys();
List<V> Values();
Scalar Length get;
Void Remove(K key);
}
builtin structure Queue<A> : Enumerable<A> {
Void Push(A item);
A Pop();
A Peek();
Void Clear();
Queue<A> Copy();
}
builtin structure Stack<A> : Enumerable<A> {
Void Push(A item);
A Pop();
A Peek();
Void Clear();
Queue<A> Copy();
}
builtin structure Range : Enumerable<Scalar> {
Scalar Start get;
Scalar Stop get;
Scalar Step get;
}
// TODO: Implement something like overload resolution. For now, there is just the most general constructor available.
builtin Range Range(Scalar start, Scalar stop, Scalar step);
builtin structure UniqueSet<A> : Enumerable<A> {
Void Add(A item);
Void Remove(A item);
Void Clear();
UniqueSet<A> Copy();
}