(* Vec: pushed, added in place, resized both ways, popped, emptied, given back; of integers and of records, which grow past the first block. *) module VecTest; import Fmt, Heap, Ints := Vec(INT), Pts := Vec(Point); type Point = record x, y: INT; name: []const U8; end; proc main*; var v: Ints.Vec; w: Pts.Vec; i, sum, top: INT; ok: BOOL; p: ^Point; s: []INT; begin Ints.init(v, Heap.heap); Fmt.print("{} {}\n", [Fmt.int(v.len), Fmt.int(LEN(Ints.all(v)))]); for i := 1 to 10000 do Ints.push(v, i); end; s := Ints.all(v); sum := 0; for i := 0 to LEN(s) - 1 do sum := sum + s[i]; end; Fmt.print("{} {} {} {}\n", [Fmt.int(v.len), Fmt.int(s[0]), Fmt.int(s[9999]), Fmt.int(sum)]); Ints.resize(v, 3); Ints.resize(v, 5); s := Ints.all(v); Fmt.print("{} {} {} {}\n", [Fmt.int(LEN(s)), Fmt.int(s[2]), Fmt.int(s[3]), Fmt.int(s[4])]); Ints.reset(v); Ints.push(v, 7); Fmt.print("{} {}\n", [Fmt.int(v.len), Fmt.int(Ints.all(v)[0])]); top, ok := Ints.pop(v); Fmt.print("{} {} {}\n", [Fmt.int(top), Fmt.bool(ok), Fmt.int(v.len)]); top, ok := Ints.pop(v); Fmt.print("{} {}\n", [Fmt.int(top), Fmt.bool(ok)]); Ints.done(v); Fmt.print("{}\n", [Fmt.int(v.len)]); Pts.init(w, Heap.heap); for i := 0 to 99 do p := Pts.add(w); p^.x := i; p^.y := i * i; end; Pts.push(w, {x: -1, y: -2, name: "last"}); Fmt.print("{} {} {} {}\n", [Fmt.int(w.len), Fmt.int(Pts.all(w)[99].y), Fmt.int(Pts.all(w)[100].x), Fmt.str(Pts.all(w)[100].name)]); Pts.done(w); end; end VecTest.