// const prime1: u32 = 73; // const prime2: u32 = 5009; export class Set { private __memory: usize; private __capacity: u32; private __size: u32; constructor() { this.__memory = 0; this.__capacity = this.__size = 0; } get size(): i32 { return this.__size; } // FIXME: not a proper set implementation, just a filler has(value: T): bool { assert(this != null); for (var index: usize = 0, limit: usize = this.__size; index < limit; ++index) if (load(this.__memory + index * sizeof()) == value) return true; return false; } add(value: T): Set { assert(this != null); if (this.__size >= this.__capacity) { var newCapacity = max(this.__capacity << 1, 8); var newMemory = allocate_memory(newCapacity * sizeof()); if (this.__memory) { move_memory(newMemory, this.__memory, this.__capacity * sizeof()); free_memory(this.__memory); } this.__capacity = newCapacity; this.__memory = newMemory; } store(this.__memory + this.__size * sizeof(), value); ++this.__size; return this; } delete(value: T): bool { assert(this != null); for (var index: usize = 0, limit: usize = this.__size; index < limit; ++index) if (load(this.__memory + index * sizeof()) == value) { if (index + 1 < this.__size) move_memory(this.__memory + index * sizeof(), this.__memory + (index + 1) * sizeof(), this.__size - index - 1); --this.__size; return true; } return false; } clear(): void { assert(this != null); this.__size = 0; } // TODO: think about iterators }