-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesign_slice.txt
190 lines (141 loc) · 3.36 KB
/
design_slice.txt
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//TODO:
How append interacts with a iterator.
Add new slice structures.
Add error reporting.
Keep NewList Options parameter?
package sindex
/*
Use:
----
type userList list.Slice
func (u *userList) Slice() (r []user) {
return u.Make(r).([]user)[:u.Len()]
}
func (u *userList) Access() (r []user) {
return u.Make(r).([]user)[:u.Len()]
}
func blah() {
u := list.NewSliceList(&userList{data:make([]user, 0, 100)}).(*userList)
u.data[u.Append()] = user{name: "donny k"}
u.data[u.Append()] = user{name: "vito"}
u.data[u.Append()] = user{name: "ralphie"}
all := getUsers()
for iter := u.Iterator(0); iter.Next(); {
all.data[all.Append()] = u.data[iter.Pos()]
}
}
func old() {
u := make([]user, 0, 100)
u = append(u, user{name: "donny k"})
u = append(u, user{name: "vito"})
u = append(u, user{name: "ralphie"})
all := getUsers()
for i, v := range u {
all = append(all, v)
}
}
type userList struct {
data []user
list.Slice
}
func blah2() {
u := list.NewSliceList(&userList{}, 100).(*userList)
u.data[u.Append()] = user{name: "donny k"}
u.data[u.Append()] = user{name: "vito"}
u.data[u.Append()] = user{name: "ralphie"}
all := getUsers()
for u.Len() != 0 {
for iter := all.Iterator(0); iter.Next() && u.Len() != 0; {
if all.data[iter.Pos()].rank == "capo" {
all.data[iter.Insert()] = u.data[u.Pos(0)]
u.Remove(0)
}
}
}
}
func blah3() {
l := list.NewSliceList(&lineList{}, 100).(*lineList)
l2 := list.NewSliceList(&lineList{}, 100).(*lineList)
iter := l.Iterator(0)
iter2 := l2.Iterator(0)
A: for iter.Next() {
for iter2.Next() {
if l.data[l.Pos()] > l2.data[l.Pos()] {
l.data[l.Insert()] = l2.data[l.Pos()]
} else {
break A
}
}
break
}
}
func old2() {
u := make([]user, 0, 100)
u = append(u, user{name: "donny k"})
u = append(u, user{name: "vito"})
u = append(u, user{name: "ralphie"})
all := getUsers()
for len(u) != 0 {
inserCount := 0
for i := 0; i < len(all); i++ {
p := i + inserCount
if all[p].rank == "capo" {
all = append(all, user{})
copy(all[p+1:], all[p:])
all[p] = u[0]
u := u[1:len(u)]
insertCount++
}
}
}
}
general remove
list.Remove(3)
list = append(list[:3], list[3+1: len(list)]...)
want funcs for remove, insert, iterate
func new2() {
u := make([]user, 0, 100)
u = append(u, user{name: "donny k"})
u = append(u, user{name: "vito"})
u = append(u, user{name: "ralphie"})
iter2 := list.Iterator(0, len(u))
all := getUsers()
for len(u) != 0 {
for iter := list.Iterator(0, len(all)); iter.Next(); {
if all[iter.Pos].rank == "capo" {
iter2.Next()
all = append(all, user{})
iter.Insert(all, u[iter2.Pos])
iter2.Remove()
u = u[:len(u)-1]
copy(all[iter.Pos:], all[iter.Pos-1:])
all[iter.Pos-1] = u[iter2.Pos]
u = append(u[:iter2.Remove()], u[iter2.Remove()+1]...)
}
}
}
}
SliceInsert(all,
func altnew2() {
u := &userList{}
u.Slice()[u.Append()] = user{name: "donny k"}
u.Slice()[u.Append()] = user{name: "vito"}
u.Slice()[u.Append()] = user{name: "ralphie"}
all := getUsers()
for u.Len() != 0 {
for iter := all.Iterator(0); iter.Next() && u.Len() != 0; {
if all.Slice()[iter.Pos()].rank == "capo" {
all.Slice()[iter.Insert()] = u.Slice()[0]
u.Remove(0)
}
}
}
}
// all = append(all, user{})
// all[iter.Insert()] = u[iter2.Pos()]
user
*/
type Slice struct {
len int
slice interface{}
}