src/common/list.odin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
package common
import "core:container/intrusive/list"
import "core:fmt"
ListLinSearch :: proc(l: list.List, item: ^$E) -> (^E, bool) {
it := list.iterator_head(l, type_of(item^), "node")
for e in list.iterate_next(&it) {
if item.value == e.value do return (^E)(e), true
}
return nil, false
}
UniqueAppend :: proc(l: ^list.List, item: ^$E) -> bool {
_, found := ListLinSearch(l^, item)
if !found {
list.push_back(l, &item.node)
return true
} else do return false
}
ListRemove :: proc(l: ^list.List, item: ^$E) -> bool {
element, found := ListLinSearch(l^, item)
if found {
list.remove(l,&element.node)
return true
} else do return false
}
ListPrint :: proc(l: ^list.List) {
if list.is_empty(l) {
return
}
it := list.iterator_head(l^, NodeEntity, "node")
for e in list.iterate_next(&it) {
fmt.println(e.value)
}
}
|