Lines Matching refs:list

37 	list := &List{}
39 list.Add(values...)
41 return list
45 func (list *List) Add(values ...interface{}) {
46 list.growBy(len(values))
48 list.elements[list.size] = value
49 list.size++
55 func (list *List) Get(index int) (interface{}, bool) {
57 if !list.withinRange(index) {
61 return list.elements[index], true
65 func (list *List) Remove(index int) {
67 if !list.withinRange(index) {
71 list.elements[index] = nil // cleanup reference
72 …copy(list.elements[index:], list.elements[index+1:list.size]) // shift to the left by one (slow op…
73 list.size--
75 list.shrink()
82 func (list *List) Contains(values ...interface{}) bool {
86 for _, element := range list.elements {
100 func (list *List) Values() []interface{} {
101 newElements := make([]interface{}, list.size, list.size)
102 copy(newElements, list.elements[:list.size])
107 func (list *List) IndexOf(value interface{}) int {
108 if list.size == 0 {
111 for index, element := range list.elements {
120 func (list *List) Empty() bool {
121 return list.size == 0
125 func (list *List) Size() int {
126 return list.size
130 func (list *List) Clear() {
131 list.size = 0
132 list.elements = []interface{}{}
136 func (list *List) Sort(comparator utils.Comparator) {
137 if len(list.elements) < 2 {
140 utils.Sort(list.elements[:list.size], comparator)
144 func (list *List) Swap(i, j int) {
145 if list.withinRange(i) && list.withinRange(j) {
146 list.elements[i], list.elements[j] = list.elements[j], list.elements[i]
153 func (list *List) Insert(index int, values ...interface{}) {
155 if !list.withinRange(index) {
157 if index == list.size {
158 list.Add(values...)
164 list.growBy(l)
165 list.size += l
166 copy(list.elements[index+l:], list.elements[index:list.size-l])
167 copy(list.elements[index:], values)
173 func (list *List) Set(index int, value interface{}) {
175 if !list.withinRange(index) {
177 if index == list.size {
178 list.Add(value)
183 list.elements[index] = value
187 func (list *List) String() string {
190 for _, value := range list.elements[:list.size] {
198 func (list *List) withinRange(index int) bool {
199 return index >= 0 && index < list.size
202 func (list *List) resize(cap int) {
204 copy(newElements, list.elements)
205 list.elements = newElements
209 func (list *List) growBy(n int) {
211 currentCapacity := cap(list.elements)
212 if list.size+n >= currentCapacity {
214 list.resize(newCapacity)
219 func (list *List) shrink() {
224 currentCapacity := cap(list.elements)
225 if list.size <= int(float32(currentCapacity)*shrinkFactor) {
226 list.resize(list.size)