.
This commit is contained in:
parent
7ba85cc2ea
commit
606bf14ffe
3 changed files with 33 additions and 2 deletions
30
array/dynamic_array.jai
Normal file
30
array/dynamic_array.jai
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
// @todo(judah): replace array_add
|
||||||
|
|
||||||
|
append :: inline (arr: *[..]$T, value: T) -> *T {
|
||||||
|
ptr := basic.array_add(arr);
|
||||||
|
ptr.* = value;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
append :: inline (arr: *[..]$T, values: ..T) -> *T {
|
||||||
|
count := arr.count;
|
||||||
|
basic.array_add(arr, ..values);
|
||||||
|
return *arr.data[count];
|
||||||
|
}
|
||||||
|
|
||||||
|
append :: inline (arr: *[..]$T) -> *T {
|
||||||
|
return basic.array_add(arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
reset :: inline (arr: *[..]$T, $keep_memory := true) {
|
||||||
|
arr.count = 0;
|
||||||
|
#if !keep_memory {
|
||||||
|
mem.release_memory(arr.data,, allocator = arr.allocator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#scope_file;
|
||||||
|
|
||||||
|
mem :: #import "jc/memory";
|
||||||
|
basic :: #import "Basic"; // @future
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#module_parameters(RUN_TESTS := false);
|
#module_parameters(RUN_TESTS := false);
|
||||||
|
|
||||||
#load "static_array.jai";
|
#load "static_array.jai";
|
||||||
|
#load "dynamic_array.jai";
|
||||||
|
|
||||||
#scope_module;
|
#scope_module;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ operator []= :: inline (a: *Static_Array, index: int, value: a.T, loc := #caller
|
||||||
|
|
||||||
for_expansion :: (a: *Static_Array, body: Code, flags: For_Flags) #expand {
|
for_expansion :: (a: *Static_Array, body: Code, flags: For_Flags) #expand {
|
||||||
view := make_view(a);
|
view := make_view(a);
|
||||||
for *=(flags & .POINTER == .POINTEr) <=(flags & .REVERSE == .REVERSE) `it, `it_index: iter {
|
for *=(flags & .POINTER == .POINTER) <=(flags & .REVERSE == .REVERSE) `it, `it_index: view {
|
||||||
#insert,scope(body)(break = break it) body;
|
#insert,scope(body)(break = break it) body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -78,7 +78,7 @@ make_dynamic :: (a: *Static_Array) -> [..]a.T {
|
||||||
#scope_file;
|
#scope_file;
|
||||||
|
|
||||||
ensure_array_has_room :: (array: *Static_Array, count: int, loc := #caller_location) #expand {
|
ensure_array_has_room :: (array: *Static_Array, count: int, loc := #caller_location) #expand {
|
||||||
basic.assert(array.count + count <= array.capacity, "attempt to add too many elements! want: %, Max: %", array.count + count, array.capacity, loc = loc);
|
basic.assert(array.count + count <= array.capacity, "attempt to add too many elements! want: %, max: %", array.count + count, array.capacity, loc = loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
mem :: #import "jc/memory";
|
mem :: #import "jc/memory";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue