summaryrefslogtreecommitdiff
path: root/tnslc/vector.tnsl
blob: 529e3a29434656fe0606e3732e85cbda14cda647 (plain)
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
struct Vector {
	~void data,
	uint
		count,
		size,
		_elsz
}

uint VECTOR_MIN_ELEMENTS = 4
~void NULL = 0

~uint8 NUM_STR = "Num %d\n\0"

/; method Vector
	
	/; init (uint elsz)
		self._elsz = elsz
		self.size = VECTOR_MIN_ELEMENTS
		self.count = 0
		self.data = _alloc(self.size * self._elsz)
	;/

	/; get (uint index) [~void]
		/; if (index !< self.count)
			return NULL
		;/

		return self.data + index * self._elsz
	;/

	/; end
		self.count = 0
		self.size = 0
		self._elsz = 0
		_delete(self.data)
	;/
;/