github.com/djordje200179/extendedlibrary/datastructures@v1.7.1-0.20240227175559-d09520a92dd4/README.md (about) 1 # Data structures 2 3 Java-like object-oriented data structures for Go. 4 Every type implements the most commonly used methods for it. 5 6 ## Types 7 This package implements many generic data structures: 8 - Collections 9 - Array 10 - Linked list 11 - Bitarray 12 - Concurrent linked list 13 - Read-only wrapper 14 - Concurrent wrapper 15 - Maps 16 - Red-black tree (binary search tree) 17 - Hashmap 18 - Linked wrapper 19 - Read-only wrapper 20 - Concurrent wrapper 21 - Sets 22 - Hashset 23 - Tree set 24 - Bitarray set 25 - Read-only wrapper 26 - Sequences 27 - Bounded buffer 28 - Linked list deque 29 - Array deque 30 - Priority queue 31 - Other 32 - Matrix 33 34 ## Iteration 35 36 ### Iterators 37 Collection, maps and sets support iterations through common `Iterable` interface, 38 that fits well into `for` loop. 39 40 ```go 41 for it := list.Iterator(); it.Valid(); it.Next() { 42 value := it.Get(); 43 } 44 ``` 45 Be aware that this kind of iterator supports only reading elements, not modifying them. 46 To modify elements, you need to get a special iterator for that kind of collection. 47 They also have specialized methods to modify structure (like insertion before the 48 current element in a linked list). 49 And through them, you can also access the element directly by reference (pointer). 50 51 ### Streams 52 Collection, maps and sets support value streaming through Go 1.22 53 range over func functionality. 54 55 ```go 56 for val := range collection.Stream { 57 58 } 59 ``` 60 61 Collections and maps also support getting a stream of references (pointers) 62 to elements, so you don't need to copy huge structure elements 63 64 ## Construction 65 66 ### Constructors 67 Every type has one or more constructors that allow you to create new instances of 68 the type. 69 70 ```go 71 arr1 := array.New[T]() 72 arr2 := array.NewWithCapacity[T](capacity) 73 hmap := hashmap.NewWithCapacity[T](capacity) 74 list := linklist.NewFromIterable[T](iterable) 75 ``` 76 77 ### Casts 78 Some types use others as their internal representation (slices, built-in maps, etc.). 79 Therefore, those types have constructors that allow you to create them from underlying types. 80 81 ```go 82 arr := array.FromSlice[T](slice) 83 set := mapset.FromMap(hashmap) 84 queue := boundedbuffer.FromChannel(ch) 85 ``` 86 87 ### Streams 88 You can also collect every finite stream into a suitable collection. 89 90 ```go 91 stream := streams.New(suppliers.Range(0, 100)) 92 iter := iter.StreamIterable(stream) 93 arr := array.NewFromIterable[T](iter) 94 ```