aboutsummaryrefslogtreecommitdiff
path: root/core/container/intrusive/list/doc.odin
blob: a50c27216a0d30037dff5d99e724a63880f613c9 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
/*
An intrusive doubly-linked list.

The intrusive container requires a `Node` to be embedded in your own structure, like this.
Example:
	My_String :: struct {
		node:  list.Node,
		value: string,
	}

Embedding the members of a `list.Node` in your structure with the `using` keyword is also allowed.
Example:
	My_String :: struct {
		using node: list.Node,
		value: string,
	}

Here is a full example.
Example:
	package test
	
	import "core:fmt"
	import "core:container/intrusive/list"
	
	main :: proc() {
	    l: list.List
	
	    one := My_String{value="Hello"}
	    two := My_String{value="World"}
	
	    list.push_back(&l, &one.node)
	    list.push_back(&l, &two.node)
	
	    iter := list.iterator_head(l, My_String, "node")
	    for s in list.iterate_next(&iter) {
	        fmt.println(s.value)
	    }
	}
	
	My_String :: struct {
	    node:  list.Node,
	    value: string,
	}

Output:
	Hello
	World
*/
package container_intrusive_list