organize static array
This commit is contained in:
parent
640519a5fa
commit
3045cda7a3
1 changed files with 22 additions and 22 deletions
|
|
@ -5,28 +5,6 @@ Static_Array :: struct(capacity: int, T: Type) {
|
||||||
Default :: #run mem.default_of(T);
|
Default :: #run mem.default_of(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
operator [] :: inline (a: Static_Array, $$index: int, loc := #caller_location) -> a.T #no_abc {
|
|
||||||
meta.check_bounds(index, a.count, loc = loc);
|
|
||||||
return a.items[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
operator *[] :: inline (a: *Static_Array, $$index: int, loc := #caller_location) -> *a.T #no_abc {
|
|
||||||
meta.check_bounds(index, a.count, loc = loc);
|
|
||||||
return *a.items[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
operator []= :: inline (a: *Static_Array, $$index: int, value: a.T, loc := #caller_location) #no_abc {
|
|
||||||
meta.check_bounds(index, a.count, loc = loc);
|
|
||||||
a.items[index] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
for_expansion :: (a: *Static_Array, body: Code, flags: For_Flags) #expand {
|
|
||||||
view := make_view(a);
|
|
||||||
for *=(flags & .POINTER == .POINTER) <=(flags & .REVERSE == .REVERSE) `it, `it_index: view {
|
|
||||||
#insert,scope(body)(break = break it) body;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
append :: inline (a: *Static_Array, item: a.T) -> *a.T #no_abc {
|
append :: inline (a: *Static_Array, item: a.T) -> *a.T #no_abc {
|
||||||
ensure_array_has_room(a, 1);
|
ensure_array_has_room(a, 1);
|
||||||
ptr := *a.items[a.count];
|
ptr := *a.items[a.count];
|
||||||
|
|
@ -55,6 +33,28 @@ reset :: inline (a: *Static_Array) #no_abc {
|
||||||
a.count = 0;
|
a.count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator [] :: inline (a: Static_Array, $$index: int, loc := #caller_location) -> a.T #no_abc {
|
||||||
|
meta.check_bounds(index, a.count, loc = loc);
|
||||||
|
return a.items[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
operator *[] :: inline (a: *Static_Array, $$index: int, loc := #caller_location) -> *a.T #no_abc {
|
||||||
|
meta.check_bounds(index, a.count, loc = loc);
|
||||||
|
return *a.items[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
operator []= :: inline (a: *Static_Array, $$index: int, value: a.T, loc := #caller_location) #no_abc {
|
||||||
|
meta.check_bounds(index, a.count, loc = loc);
|
||||||
|
a.items[index] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
for_expansion :: (a: *Static_Array, body: Code, flags: For_Flags) #expand {
|
||||||
|
view := make_view(a);
|
||||||
|
for *=(flags & .POINTER == .POINTER) <=(flags & .REVERSE == .REVERSE) `it, `it_index: view {
|
||||||
|
#insert,scope(body)(break = break it) body;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
make_view :: (a: Static_Array) -> []a.T {
|
make_view :: (a: Static_Array) -> []a.T {
|
||||||
view := a.items.([]a.T);
|
view := a.items.([]a.T);
|
||||||
view.count = a.count;
|
view.count = a.count;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue