Skip to content

Commit

Permalink
remove Indirect_Array
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtomsu committed Oct 22, 2024
1 parent 9983d4e commit d381140
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 167 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Name | Similar To | Info
Array | `[dynamic]T` or `core:container/small_array` | Regular static array with dynamic number of elements (`[N]T` + `int` for length)
Soa_Array | `#soa[dynamic]T` | Variant of `Array` with `#soa` backing buffer
Pool | none | A sparse array, which uses [Handles](#handles) to refer to elements. Deleted elements are kept in a free list. All operations are O(1). Overhead is one index and one generation counter per item.
Indirect_Array | `map[Handle]T` | Uses a Pool to remap Handles into a regular linear array of values. All operations are O(1). Overhead is two indexes and one generation counter per item.
Queue | core:container/queue | A simple ring-buffer based queue.
Bit_Array | bit_set for >128 element support | Array of booleans stored as single bits. This can be useful in cases where `bit_set` is too small (>128 elements).

Expand Down Expand Up @@ -58,7 +57,7 @@ game_draw :: proc(game: Game) {
```

## Handles
Pool and Indirect_Array use Handles to address items. A handle is sort of like a unique ID, however it can optionally also have a "generation index". This is useful because IDs can be reused, but the generation index check makes sure you are accessing the item you _think_ you are. This prevents "use-after-removed" kinds of bugs.
Pool uses Handles to address items. A handle is sort of like a unique ID, however it can optionally also have a "generation index". This is useful because IDs can be reused, but the generation index check makes sure you are accessing the item you _think_ you are. This prevents "use-after-removed" kinds of bugs.

I recommend reading this blog post by Andre Weissflog to learn more about the benefits of Handles: [Handles are the better pointers](https://floooh.github.io/2018/06/17/handles-vs-pointers.html)

Expand Down
16 changes: 0 additions & 16 deletions demo/demo.odin
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,5 @@ main :: proc() {
sds.pool_remove(&ds, first)
}

{
Handle :: sds.Handle(u16, u16)
ds: sds.Indirect_Array(1024, f32, Handle)
first := sds.indirect_array_append(&ds, 1.23)
_ = sds.indirect_array_slice(&ds)
sds.indirect_array_set(&ds, first, 10)
sds.indirect_array_set_safe(&ds, Handle{}, 120)
_ = sds.indirect_array_get(ds, first)
_ = sds.indirect_array_get_safe(ds, Handle{})
_ = sds.indirect_array_get_ptr(&ds, first)
_ = sds.indirect_array_get_ptr_safe(&ds, Handle{})
assert(sds.indirect_array_has_handle(ds, first))
assert(sds.indirect_array_has_index(ds, 0))
sds.indirect_array_remove(&ds, first)
}

fmt.println("Done!")
}
138 changes: 0 additions & 138 deletions indirect_array.odin

This file was deleted.

11 changes: 0 additions & 11 deletions sds.odin
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ package sds
slice :: proc {
array_slice,
soa_array_slice,
indirect_array_slice,
}

set :: proc {
array_set,
soa_array_set,
pool_set,
indirect_array_set,
queue_set,
bit_array_set,
}
Expand All @@ -21,7 +19,6 @@ set_safe :: proc {
array_set_safe,
soa_array_set_safe,
pool_set_safe,
indirect_array_set_safe,
queue_set_safe,
bit_array_set_safe,
}
Expand All @@ -30,7 +27,6 @@ get :: proc {
array_get,
soa_array_get,
pool_get,
indirect_array_get,
queue_get,
bit_array_get,
}
Expand All @@ -39,7 +35,6 @@ get_safe :: proc {
array_get_safe,
soa_array_get_safe,
pool_get_safe,
indirect_array_get_safe,
queue_get_safe,
bit_array_get_safe,
}
Expand All @@ -48,35 +43,30 @@ get_ptr :: proc {
array_get_ptr,
soa_array_get_ptr,
pool_get_ptr,
indirect_array_get_ptr,
queue_get_ptr,
}

get_ptr_safe :: proc {
array_get_ptr_safe,
soa_array_get_ptr_safe,
pool_get_ptr_safe,
indirect_array_get_ptr_safe,
queue_get_ptr_safe,
}

has_index :: proc {
array_has_index,
soa_array_has_index,
pool_has_index,
indirect_array_has_index,
}

has_handle :: proc {
pool_has_handle,
indirect_array_has_handle,
}

append :: proc {
array_append,
soa_array_append,
pool_append,
indirect_array_append,
queue_push_back,
}

Expand Down Expand Up @@ -116,5 +106,4 @@ remove :: proc {
array_remove,
soa_array_remove,
pool_remove,
indirect_array_remove,
}

0 comments on commit d381140

Please sign in to comment.