diff options
| author | gingerBill <bill@gingerbill.org> | 2020-04-19 21:45:04 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-04-19 21:45:04 +0100 |
| commit | 97f7a558faaf206bb7d10eaf3adce99322fd9541 (patch) | |
| tree | 2a3e8f91525692f14de4064751efae62699f10bb /core/container | |
| parent | 2c91c21021e1c4d1d675ee430e0d7ccf88e882be (diff) | |
`#optional_ok` tag for procedures
Diffstat (limited to 'core/container')
| -rw-r--r-- | core/container/array.odin | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/core/container/array.odin b/core/container/array.odin index 273657eb6..123440b2e 100644 --- a/core/container/array.odin +++ b/core/container/array.odin @@ -47,10 +47,16 @@ array_slice :: proc(a: $A/Array($T)) -> []T { array_get :: proc(a: $A/Array($T), index: int) -> T { + assert(uint(index) < a.len); return (^T)(uintptr(a.data) + size_of(T)*uintptr(index))^; } +array_get_ptr :: proc(a: $A/Array($T), index: int) -> ^T { + assert(uint(index) < a.len); + return (^T)(uintptr(a.data) + size_of(T)*uintptr(index)); +} array_set :: proc(a: ^$A/Array($T), index: int, item: T) { + assert(uint(index) < a.len); (^T)(uintptr(a.data) + size_of(T)*uintptr(index))^ = item; } @@ -122,7 +128,7 @@ array_clear :: proc(q: ^$Q/Queue($T)) { } -array_push :: proc(a: ^$A/Array($T), items: ..T) { +array_push_back_elems :: proc(a: ^$A/Array($T), items: ..T) { if array_space(a^) < len(items) { array_grow(a, a.size + len(items)); } @@ -133,6 +139,8 @@ array_push :: proc(a: ^$A/Array($T), items: ..T) { a.len = offset + n; } +array_push :: proc{array_push_back, array_push_back_elems}; +array_append :: proc{array_push_back, array_push_back_elems}; array_set_capacity :: proc(a: ^$A/Array($T), new_capacity: int) { if new_capacity == a.cap { |