summaryrefslogtreecommitdiff
path: root/tnslc/vector.tnsl
diff options
context:
space:
mode:
Diffstat (limited to 'tnslc/vector.tnsl')
-rw-r--r--tnslc/vector.tnsl100
1 files changed, 0 insertions, 100 deletions
diff --git a/tnslc/vector.tnsl b/tnslc/vector.tnsl
deleted file mode 100644
index 9401508..0000000
--- a/tnslc/vector.tnsl
+++ /dev/null
@@ -1,100 +0,0 @@
-# 32 bytes long
-struct Vector {
- uint
- el_size,
- num_el,
- dat_size,
- ~uint8 dat
-}
-
-/; method Vector
-
- /; resize (uint num_el)
- self.dat_size = num_el
- self.dat = _realloc(self.dat, num_el * self.el_size)
- ;/
-
- /; get (uint i) [~uint8]
- /; if (i !< self.num_el)
- return self.dat
- ;/
- return self.dat + (i * self.el_size)
- ;/
-
- /; set (uint i, ~uint8 data)
- ~uint8 index = self.get(i)
- /; loop (i = 0; i < self.el_size) [i++]
- index` = data`
- index++
- data++
- ;/
- ;/
-
- /; push (~uint8 data)
- self.num_el++
- self.set(self.num_el - 1, data)
- /; if (self.num_el !< self.dat_size)
- self.resize(2 * self.dat_size)
- ;/
- ;/
-
- /; pop
- self.num_el--
- /; if (self.num_el > 0 && self.num_el < self.dat_size / 4)
- self.resize(self.dat_size / 2)
- ;; else if (self.num_el < 0)
- self.num_el = 0
- ;/
- ;/
-
- /; remove (int index)
- index++
- /; loop (index < self.num_el) [index++]
- self.set(index - 1, self.get(index))
- ;/
- self.pop()
- ;/
-
- /; copy (Vector v)
- self.dat_size = v.dat_size
- self.num_el = v.num_el
- self.el_size = v.el_size
- self.dat = _alloc(self.dat_size * self.el_size)
-
- /; loop (int i = 0; i < self.num_el) [i++]
- self.set(i, v.dat + i * self.el_size)
- ;/
- ;/
-
- /; add (Vector v)
- /; loop (int i = 0; i < v._len()) [i++]
- self.push(v.get(i))
- ;/
- ;/
-
- # [UNSAFE] ONLY USE FOR STRING VECTORS
- /; add_str (~uint8 dat)
- /; loop (int i = 0; dat{i} !== 0) [i++]
- self.push(dat + i)
- ;/
- ;/
-
- /; start (int el_size)
- self.num_el = 0
- self.el_size = el_size
- self.dat_size = 1
- self.dat = _alloc(self.el_size)
- ;/
-
- /; _len [uint]
- return self.num_el
- ;/
-
- /; _del
- self.num_el = 0
- self.el_size = 0
- self.dat_size = 0
- _delete(self.dat)
- self.dat = 0
- ;/
-;/