// this reason, most allocator also support allocating their data from the context's
// allocator simply by passing that allocator as an arugment.
+ //
+ // BUG: This is not a thread-safe allocator!!
+ // Why not use context.temp_allocator?
+ //
+
+ /*
iter_ring_buffer: [1024] u8;
iter_ring: alloc.ring.RingState;
iter_allocator: Allocator;
iter_ring = alloc.ring.make(iter_ring_buffer);
iter_allocator = alloc.as_allocator(^iter_ring);
}
+ */
}
as_iterator :: #match {}
filter :: #match #local {}
#overload
-filter :: (it: Iterator($T), predicate: (T) -> bool, allocator := iter_allocator) -> Iterator(T) {
+filter :: (it: Iterator($T), predicate: (T) -> bool, allocator := context.temp_allocator) -> Iterator(T) {
FilterIterator :: struct (T: type_expr) {
iterator: Iterator(T);
predicate: (T) -> bool;
}
#overload
-filter :: (it: Iterator($T), ctx: $Ctx, predicate: (T, Ctx) -> bool, allocator := iter_allocator) -> Iterator(T) {
+filter :: (it: Iterator($T), ctx: $Ctx, predicate: (T, Ctx) -> bool, allocator := context.temp_allocator) -> Iterator(T) {
FilterIterator :: struct (T: type_expr, Ctx: type_expr) {
iterator: Iterator(T);
predicate: (T, Ctx) -> bool;
map :: #match #local {}
#overload
-map :: (it: Iterator($T), transform: (T) -> $R, allocator := iter_allocator) -> Iterator(R) {
+map :: (it: Iterator($T), transform: (T) -> $R, allocator := context.temp_allocator) -> Iterator(R) {
MapIterator :: struct (T: type_expr, R: type_expr) {
iterator: Iterator(T);
transform: (T) -> R;
}
#overload
-map :: (it: Iterator($T), ctx: $Ctx, transform: (T, Ctx) -> $R, allocator := iter_allocator) -> Iterator(R) {
+map :: (it: Iterator($T), ctx: $Ctx, transform: (T, Ctx) -> $R, allocator := context.temp_allocator) -> Iterator(R) {
MapIterator :: struct (T: type_expr, R: type_expr, Ctx: type_expr) {
iterator: Iterator(T);
transform: (T, Ctx) -> R;
return !cont;
}
-take :: (it: Iterator($T), count: u32, allocator := iter_allocator) -> Iterator(T) {
+take :: (it: Iterator($T), count: u32, allocator := context.temp_allocator) -> Iterator(T) {
TakeIterator :: struct (T: type_expr) {
iterator: Iterator(T);
remaining: u32;
};
}
-take_while :: (it: Iterator($T), predicate: (T) -> bool, allocator := iter_allocator) -> Iterator(T) {
+take_while :: (it: Iterator($T), predicate: (T) -> bool, allocator := context.temp_allocator) -> Iterator(T) {
TakeIterator :: struct (T: type_expr) {
iterator: Iterator(T);
predicate: (T) -> bool;
};
}
-skip :: (it: Iterator($T), count: u32, allocator := iter_allocator) -> Iterator(T) {
+skip :: (it: Iterator($T), count: u32, allocator := context.temp_allocator) -> Iterator(T) {
SkipIterator :: struct (T: type_expr) {
iterator: Iterator(T);
to_skip: i32;
second: R;
}
-zip :: (left_iterator: Iterator($T), right_iterator: Iterator($R), allocator := iter_allocator) -> Iterator(Zipped(T, R)) {
+zip :: (left_iterator: Iterator($T), right_iterator: Iterator($R), allocator := context.temp_allocator) -> Iterator(Zipped(T, R)) {
ZippedIterator :: struct (T: type_expr, R: type_expr) {
iterator1: Iterator(T);
iterator2: Iterator(R);
idx: u32;
}
- c := new(Context(T), allocator=iter_allocator);
- c.iters = memory.copy_slice(iters, allocator=iter_allocator);
+ c := new(Context(T), allocator=context.temp_allocator);
+ c.iters = memory.copy_slice(iters, allocator=context.temp_allocator);
c.idx = 0;
next :: (use c: ^Context($T)) -> (T, bool) {
return *(cast(^T) data), true;
}
- allocated := cast(^T) raw_alloc(iter_allocator, sizeof T);
+ allocated := cast(^T) raw_alloc(context.temp_allocator, sizeof T);
*allocated = value;
return .{
current_index: i32;
}
- ec := make(Enumeration_Context(T), allocator=iter_allocator);
+ ec := make(Enumeration_Context(T), allocator=context.temp_allocator);
ec.iterator = it;
ec.current_index = start_index;
current: u32;
}
- c := make(Context(T), allocator=iter_allocator);
+ c := make(Context(T), allocator=context.temp_allocator);
c.data = arr.data;
c.count = arr.count;
c.current = 0;
current: u32;
}
- c := make(Context(T), allocator=iter_allocator);
+ c := make(Context(T), allocator=context.temp_allocator);
c.arr = x;
c.current = 0;
current: u32;
}
- c := make(Context(T), allocator=iter_allocator);
+ c := make(Context(T), allocator=context.temp_allocator);
c.arr = x;
c.current = 0;
}
}
- c := new(Context, allocator=iter_allocator);
+ c := new(Context, allocator=context.temp_allocator);
c.r = r;
c.v = r.low;