Skip to content

Commit 334a167

Browse files
committed
gofmt
Signed-off-by: Tim Henderson <[email protected]>
1 parent cd47fff commit 334a167

17 files changed

+54
-94
lines changed

cast_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package data_structures
33
import "testing"
44
import (
55
"github.com/timtadh/data-structures/hashtable"
6-
"github.com/timtadh/data-structures/set"
76
"github.com/timtadh/data-structures/list"
7+
"github.com/timtadh/data-structures/set"
88
"github.com/timtadh/data-structures/tree/avl"
99
"github.com/timtadh/data-structures/tree/bptree"
1010
"github.com/timtadh/data-structures/trie"

errors/errors.go

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strings"
88
)
99

10-
1110
var SkipLogging map[string]bool
1211

1312
func init() {
@@ -104,4 +103,3 @@ var Errors map[string]ErrorFmter = map[string]ErrorFmter{
104103
"negative-size": NegativeSize,
105104
"bptree-error": BpTreeError,
106105
}
107-

list/array_list.go

+11-13
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@ import (
1111
)
1212

1313
import (
14-
"github.com/timtadh/data-structures/types"
1514
"github.com/timtadh/data-structures/errors"
15+
"github.com/timtadh/data-structures/types"
1616
)
1717

18-
19-
2018
type MList struct {
2119
List
22-
MarshalItem types.ItemMarshal
20+
MarshalItem types.ItemMarshal
2321
UnmarshalItem types.ItemUnmarshal
2422
}
2523

2624
func NewMList(list *List, marshal types.ItemMarshal, unmarshal types.ItemUnmarshal) *MList {
2725
return &MList{
28-
List: *list,
29-
MarshalItem: marshal,
26+
List: *list,
27+
MarshalItem: marshal,
3028
UnmarshalItem: unmarshal,
3129
}
3230
}
@@ -57,7 +55,7 @@ func (m *MList) MarshalBinary() ([]byte, error) {
5755
return bytes.Join(items, []byte{}), nil
5856
}
5957

60-
func (m *MList) UnmarshalBinary(bytes []byte) (error) {
58+
func (m *MList) UnmarshalBinary(bytes []byte) error {
6159
m.List.fixed = bytes[0] == 1
6260
_cap := int(binary.LittleEndian.Uint32(bytes[1:5]))
6361
size := int(binary.LittleEndian.Uint32(bytes[5:9]))
@@ -123,7 +121,7 @@ func (s *Sortable) Swap(i, j int) {
123121
}
124122

125123
type List struct {
126-
list []types.Hashable
124+
list []types.Hashable
127125
fixed bool
128126
}
129127

@@ -139,7 +137,7 @@ func Fixed(size int) *List {
139137

140138
func newList(initialSize int, fixedSize bool) *List {
141139
return &List{
142-
list: make([]types.Hashable, 0, initialSize),
140+
list: make([]types.Hashable, 0, initialSize),
143141
fixed: fixedSize,
144142
}
145143
}
@@ -309,11 +307,11 @@ func (l *List) Extend(it types.KIterator) (err error) {
309307
}
310308

311309
func (l *List) Pop() (item types.Hashable, err error) {
312-
item, err = l.Get(len(l.list)-1)
310+
item, err = l.Get(len(l.list) - 1)
313311
if err != nil {
314312
return nil, err
315313
}
316-
err = l.Remove(len(l.list)-1)
314+
err = l.Remove(len(l.list) - 1)
317315
if err != nil {
318316
return nil, err
319317
}
@@ -324,8 +322,8 @@ func (l *List) Remove(i int) error {
324322
if i < 0 || i >= len(l.list) {
325323
return errors.Errorf("Access out of bounds. len(*List) = %v, idx = %v", len(l.list), i)
326324
}
327-
dst := l.list[i:len(l.list)-1]
328-
src := l.list[i+1:len(l.list)]
325+
dst := l.list[i : len(l.list)-1]
326+
src := l.list[i+1 : len(l.list)]
329327
copy(dst, src)
330328
l.list = l.list[:len(l.list)-1]
331329
if err := l.shrink(); err != nil {

list/array_list_test.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/timtadh/data-structures/types"
1515
)
1616

17-
1817
func init() {
1918
if urandom, err := os.Open("/dev/urandom"); err != nil {
2019
panic(err)
@@ -27,7 +26,6 @@ func init() {
2726
}
2827
}
2928

30-
3129
type T testing.T
3230

3331
func (t *T) assert(msg string, oks ...bool) {
@@ -69,7 +67,7 @@ func TestAppendGet(x *testing.T) {
6967
list := New(10)
7068
items := make([]types.ByteSlice, 0, SIZE)
7169
for i := 0; i < SIZE; i++ {
72-
item := t.randslice(rand.Intn(10)+1)
70+
item := t.randslice(rand.Intn(10) + 1)
7371
items = append(items, item)
7472
t.assert_nil(list.Append(item))
7573
}
@@ -86,7 +84,7 @@ func TestAppendGetCopy(x *testing.T) {
8684
list := New(10)
8785
items := make([]types.ByteSlice, 0, SIZE)
8886
for i := 0; i < SIZE; i++ {
89-
item := t.randslice(rand.Intn(10)+1)
87+
item := t.randslice(rand.Intn(10) + 1)
9088
items = append(items, item)
9189
t.assert_nil(list.Append(item))
9290
}
@@ -109,7 +107,7 @@ func TestAppendMarshalUnmarshalGet(x *testing.T) {
109107
list := New(10)
110108
items := make([]types.Int, 0, SIZE)
111109
for i := 0; i < SIZE; i++ {
112-
item := types.Int(rand.Intn(10)+1)
110+
item := types.Int(rand.Intn(10) + 1)
113111
items = append(items, item)
114112
t.assert_nil(list.Append(item))
115113
}
@@ -206,7 +204,7 @@ func TestAppendPop(x *testing.T) {
206204
list := New(10)
207205
items := make([]types.ByteSlice, 0, SIZE)
208206
for i := 0; i < SIZE; i++ {
209-
item := t.randslice(rand.Intn(10)+1)
207+
item := t.randslice(rand.Intn(10) + 1)
210208
items = append(items, item)
211209
t.assert_nil(list.Append(item))
212210
}
@@ -224,7 +222,7 @@ func TestExtend(x *testing.T) {
224222
b := New(10)
225223
items := make([]types.ByteSlice, 0, SIZE)
226224
for i := 0; i < SIZE; i++ {
227-
item := t.randslice(rand.Intn(10)+1)
225+
item := t.randslice(rand.Intn(10) + 1)
228226
items = append(items, item)
229227
if i < SIZE/2 {
230228
t.assert_nil(a.Append(item))
@@ -278,4 +276,3 @@ func TestEqualsHash(x *testing.T) {
278276
t.assert("d.Hash() != b.Hash()", d.Hash() != b.Hash())
279277
t.assert("d.Hash() != empty.Hash()", d.Hash() != empty.Hash())
280278
}
281-

list/fixed_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ func TestFixed(x *testing.T) {
1717
list := Fixed(SIZE)
1818
items := make([]types.ByteSlice, 0, SIZE)
1919
for i := 0; i < SIZE; i++ {
20-
item := t.randslice(rand.Intn(10)+1)
20+
item := t.randslice(rand.Intn(10) + 1)
2121
items = append(items, item)
2222
t.assert_nil(list.Append(item))
2323
}
24-
t.assert(fmt.Sprintf("list.Full() (%v)", list.Full()) , list.Full())
25-
t.assert(fmt.Sprintf("list.Size == %d (%d)", SIZE, list.Size()) , list.Size() == SIZE)
24+
t.assert(fmt.Sprintf("list.Full() (%v)", list.Full()), list.Full())
25+
t.assert(fmt.Sprintf("list.Size == %d (%d)", SIZE, list.Size()), list.Size() == SIZE)
2626
err := list.Append(t.randslice(10))
2727
t.assert(fmt.Sprintf("err != nil (%v)", err), err != nil)
2828
for i, item := range items {
@@ -45,8 +45,8 @@ func TestFixedSorted(x *testing.T) {
4545
items = append(items, item)
4646
t.assert_nil(set.Add(item))
4747
}
48-
t.assert(fmt.Sprintf("set.Full() (%v)", set.Full()) , set.Full())
49-
t.assert(fmt.Sprintf("set.Size == %d (%d)", SIZE, set.Size()) , set.Size() == SIZE)
48+
t.assert(fmt.Sprintf("set.Full() (%v)", set.Full()), set.Full())
49+
t.assert(fmt.Sprintf("set.Size == %d (%d)", SIZE, set.Size()), set.Size() == SIZE)
5050
for i, item := range items {
5151
t.assert(fmt.Sprintf("i %v, !set.Has(item)", i), set.Has(item))
5252
}
@@ -64,7 +64,7 @@ func TestFixedAppendMarshalUnmarshalGet(x *testing.T) {
6464
list := Fixed(SIZE)
6565
items := make([]types.Int, 0, SIZE)
6666
for i := 0; i < SIZE; i++ {
67-
item := types.Int(rand.Intn(10)+1)
67+
item := types.Int(rand.Intn(10) + 1)
6868
items = append(items, item)
6969
t.assert_nil(list.Append(item))
7070
}

list/sorted.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
)
77

88
import (
9-
"github.com/timtadh/data-structures/types"
109
"github.com/timtadh/data-structures/errors"
10+
"github.com/timtadh/data-structures/types"
1111
)
1212

1313
type MSorted struct {
@@ -17,7 +17,7 @@ type MSorted struct {
1717

1818
func NewMSorted(s *Sorted, marshal types.ItemMarshal, unmarshal types.ItemUnmarshal) *MSorted {
1919
return &MSorted{
20-
MList: *NewMList(&s.list, marshal, unmarshal),
20+
MList: *NewMList(&s.list, marshal, unmarshal),
2121
AllowDups: s.allowDups,
2222
}
2323
}
@@ -40,7 +40,7 @@ func (m *MSorted) MarshalBinary() ([]byte, error) {
4040
return bytes.Join([][]byte{[]byte{allowDups}, b}, []byte{}), nil
4141
}
4242

43-
func (m *MSorted) UnmarshalBinary(bytes []byte) (error) {
43+
func (m *MSorted) UnmarshalBinary(bytes []byte) error {
4444
allowDups := bytes[0]
4545
if allowDups == 0 {
4646
m.AllowDups = false
@@ -51,22 +51,22 @@ func (m *MSorted) UnmarshalBinary(bytes []byte) (error) {
5151
}
5252

5353
type Sorted struct {
54-
list List
54+
list List
5555
allowDups bool
5656
}
5757

5858
// Creates a sorted list.
5959
func NewSorted(initialSize int, allowDups bool) *Sorted {
6060
return &Sorted{
61-
list: *New(initialSize),
61+
list: *New(initialSize),
6262
allowDups: allowDups,
6363
}
6464
}
6565

6666
// Creates a fixed size sorted list.
6767
func NewFixedSorted(size int, allowDups bool) *Sorted {
6868
return &Sorted{
69-
list: *Fixed(size),
69+
list: *Fixed(size),
7070
allowDups: allowDups,
7171
}
7272
}
@@ -99,7 +99,7 @@ func (s *Sorted) Empty() bool {
9999
}
100100

101101
func (s *Sorted) Copy() *Sorted {
102-
return &Sorted{ *s.list.Copy(), s.allowDups, }
102+
return &Sorted{*s.list.Copy(), s.allowDups}
103103
}
104104

105105
func (s *Sorted) Has(item types.Hashable) (has bool) {
@@ -174,7 +174,7 @@ func (s *Sorted) Items() (it types.KIterator) {
174174
return s.list.Items()
175175
}
176176

177-
func (s *Sorted) String() (string) {
177+
func (s *Sorted) String() string {
178178
return s.list.String()
179179
}
180180

@@ -192,7 +192,7 @@ func (s *Sorted) Find(item types.Hashable) (int, bool, error) {
192192
r = m - 1
193193
} else if item.Equals(im) {
194194
for j := m; j > 0; j-- {
195-
ij_1, err := s.list.Get(j-1)
195+
ij_1, err := s.list.Get(j - 1)
196196
if err != nil {
197197
return -1, false, err
198198
}
@@ -207,4 +207,3 @@ func (s *Sorted) Find(item types.Hashable) (int, bool, error) {
207207
}
208208
return l, false, nil
209209
}
210-

list/sorted_test.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ import (
1111
"github.com/timtadh/data-structures/types"
1212
)
1313

14-
1514
func TestSortedAddMarshalUnmarshalGet(x *testing.T) {
1615
t := (*T)(x)
1716
SIZE := 100
1817
list := NewSorted(10, false)
1918
items := make([]types.Int, 0, SIZE)
2019
for i := 0; i < SIZE; i++ {
21-
item := types.Int(rand.Intn(10)+1)
20+
item := types.Int(rand.Intn(10) + 1)
2221
items = append(items, item)
2322
t.assert_nil(list.Add(item))
2423
}
@@ -107,9 +106,9 @@ func TestSortedExtend(x *testing.T) {
107106
b := NewSorted(10, false)
108107
items := make([]types.ByteSlice, 0, SIZE)
109108
for i := 0; i < SIZE; i++ {
110-
item := t.randslice(rand.Intn(10)+1)
109+
item := t.randslice(rand.Intn(10) + 1)
111110
for all.Has(item) {
112-
item = t.randslice(rand.Intn(10)+1)
111+
item = t.randslice(rand.Intn(10) + 1)
113112
}
114113
items = append(items, item)
115114
t.assert_nil(all.Add(item))
@@ -127,8 +126,6 @@ func TestSortedExtend(x *testing.T) {
127126
}
128127
}
129128

130-
131-
132129
func TestSortedLess(x *testing.T) {
133130
t := (*T)(x)
134131
a := SortedFromSlice([]types.Hashable{types.Int(1), types.Int(2), types.Int(3)}, false)
@@ -167,4 +164,3 @@ func TestSortedEqualsHash(x *testing.T) {
167164
t.assert("d.Hash() != b.Hash()", d.Hash() != b.Hash())
168165
t.assert("d.Hash() != empty.Hash()", d.Hash() != empty.Hash())
169166
}
170-

set/example_serialize_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66

77
import (
88
"github.com/timtadh/data-structures/list"
9-
"github.com/timtadh/data-structures/types"
109
"github.com/timtadh/data-structures/set"
10+
"github.com/timtadh/data-structures/types"
1111
)
1212

1313
func makeSet() *set.SortedSet {

set/mapset.go

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/timtadh/data-structures/types"
1010
)
1111

12-
1312
type MapSet struct {
1413
Set types.Set
1514
}
@@ -169,4 +168,3 @@ func (m *MapSet) ProperSuperset(b types.Set) bool {
169168
func (m *MapSet) String() string {
170169
return fmt.Sprintf("%v", m.Set)
171170
}
172-

set/mapset_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,3 @@ func TestMapSetIterators(x *testing.T) {
9797
}
9898
t.assert("uneven iteration", items == nil && keys == nil)
9999
}
100-

0 commit comments

Comments
 (0)