diff --git a/std/compact_map.oc b/std/compact_map.oc index 5707566..f339d70 100644 --- a/std/compact_map.oc +++ b/std/compact_map.oc @@ -156,6 +156,8 @@ def Map::at(&this, key: K): V { return item.value } +def Map::size(&this): u32 => .items.size + def Map::contains(&this, key: K): bool { let hash = key.hash() let index = .get_index(key, hash) diff --git a/std/map.oc b/std/map.oc index d0fa1b3..4ff0980 100644 --- a/std/map.oc +++ b/std/map.oc @@ -190,6 +190,8 @@ def Map::push_keys(&this, vec: &Vector) { } } +def Map::size(&this): u32 => .num_items + //* Checks if the map is empty def Map::is_empty(&this): bool => .num_items == 0 diff --git a/std/vector.oc b/std/vector.oc index 378698a..a25567e 100644 --- a/std/vector.oc +++ b/std/vector.oc @@ -52,6 +52,19 @@ def Vector::pop(&this): T { return .data[.size] } +//* Pops an element from the given index and returns it - O(n) +def Vector::pop_at(&this, i: u32): T { + assert .size > 0, "Empty vector in Vector::pop_at" + assert i < .size, "Out of bounds in Vector::pop_at" + + let val = .data[i] + for let j = i; j < .size - 1; j += 1 { + .data[j] = .data[j + 1] + } + .size -= 1 + return val +} + //* Appends the contents of another vector to this one def Vector::extend(&this, other: &Vector) { for val : other.iter() {