From c636819142eba3b92bc856dde673ff316fa6a798 Mon Sep 17 00:00:00 2001 From: Justin Lowery Date: Tue, 4 Jul 2017 00:06:01 -0400 Subject: [PATCH] Now formatting with gofmt --- asc/error.go | 2 +- asc/numeric.go | 2 +- asc/numeric_test.go | 2 +- asc/time.go | 2 +- asc/time_test.go | 2 +- bounds.go | 4 ++-- delete.go | 6 +++--- delete_bench_test.go | 2 +- delete_test.go | 4 ++-- desc/error.go | 2 +- desc/numeric.go | 2 +- desc/numeric_test.go | 2 +- desc/time.go | 2 +- desc/time_test.go | 2 +- get.go | 2 +- get_bench_test.go | 2 +- get_test.go | 2 +- has.go | 2 +- has_bench_test.go | 2 +- has_test.go | 2 +- insert.go | 4 ++-- insert_bench_test.go | 2 +- insert_test.go | 4 ++-- insertsort.go | 2 +- iter.go | 10 +++++----- iter_test.go | 38 +++++++++++++++++++------------------- keys.go | 4 ++-- keys_test.go | 4 ++-- map.go | 2 +- replace.go | 6 +++--- replace_bench_test.go | 2 +- replace_test.go | 2 +- sliceutils.go | 10 +++++----- sortedmap.go | 2 +- sortedmap_bench_test.go | 5 +++-- sortedmap_test.go | 2 +- testing_utils_test.go | 4 ++-- 37 files changed, 76 insertions(+), 75 deletions(-) diff --git a/asc/error.go b/asc/error.go index 327d71e..df2985e 100644 --- a/asc/error.go +++ b/asc/error.go @@ -1,3 +1,3 @@ package asc -const greaterThanErr = "the higher value was less than the lesser value!" \ No newline at end of file +const greaterThanErr = "the higher value was less than the lesser value!" diff --git a/asc/numeric.go b/asc/numeric.go index 28b80e7..61d25d0 100644 --- a/asc/numeric.go +++ b/asc/numeric.go @@ -46,4 +46,4 @@ func Uint(i, j interface{}) bool { func Int(i, j interface{}) bool { return i.(int) < j.(int) -} \ No newline at end of file +} diff --git a/asc/numeric_test.go b/asc/numeric_test.go index 9fc19d7..7013ec3 100644 --- a/asc/numeric_test.go +++ b/asc/numeric_test.go @@ -72,4 +72,4 @@ func TestInt(t *testing.T) { if Int(int(1), 0) { t.Fatal("asc.TestInt failed: %v", greaterThanErr) } -} \ No newline at end of file +} diff --git a/asc/time.go b/asc/time.go index 6f57328..20104c5 100644 --- a/asc/time.go +++ b/asc/time.go @@ -4,4 +4,4 @@ import "time" func Time(i, j interface{}) bool { return i.(time.Time).Before(j.(time.Time)) -} \ No newline at end of file +} diff --git a/asc/time_test.go b/asc/time_test.go index 0c53a28..abc17df 100644 --- a/asc/time_test.go +++ b/asc/time_test.go @@ -12,4 +12,4 @@ func TestTime(t *testing.T) { if Time(laterDate, earlerDate) { t.Fatal("asc.TestTime failed: laterDate was before earlierDate") } -} \ No newline at end of file +} diff --git a/bounds.go b/bounds.go index ddd8216..0f5343d 100644 --- a/bounds.go +++ b/bounds.go @@ -22,7 +22,7 @@ func (sm *SortedMap) setBoundIdx(boundVal interface{}) int { // If the bound value is greater than or equal to the value from the map, // select the next index value. - if idx < smLen - 1 { + if idx < smLen-1 { if sm.lessFn(valFromIdx, boundVal) { idx++ } @@ -60,4 +60,4 @@ func (sm *SortedMap) boundsIdxSearch(lowerBound, upperBound interface{}) []int { lowerBoundIdx, upperBoundIdx, } -} \ No newline at end of file +} diff --git a/delete.go b/delete.go index 3637541..586e75e 100644 --- a/delete.go +++ b/delete.go @@ -12,7 +12,7 @@ func (sm *SortedMap) delete(key interface{}) bool { if i == smLen { i-- - } else if i < smLen - 1 { + } else if i < smLen-1 { i++ } for sm.sorted[i] != key { @@ -32,7 +32,7 @@ func (sm *SortedMap) boundedDelete(lowerBound, upperBound interface{}) bool { if iterBounds == nil { return false } - for i := iterBounds[0]; i <= iterBounds[1] - i; i++ { + for i := iterBounds[0]; i <= iterBounds[1]-i; i++ { delete(sm.idx, sm.sorted[i]) sm.sorted = deleteInterface(sm.sorted, i) } @@ -58,4 +58,4 @@ func (sm *SortedMap) BatchDelete(keys []interface{}) []bool { // BoundedDelete returns true if the operation was successful, or false otherwise. func (sm *SortedMap) BoundedDelete(lowerBound, upperBound interface{}) bool { return sm.boundedDelete(lowerBound, upperBound) -} \ No newline at end of file +} diff --git a/delete_bench_test.go b/delete_bench_test.go index b5c7819..c9eeb6d 100644 --- a/delete_bench_test.go +++ b/delete_bench_test.go @@ -74,4 +74,4 @@ func BenchmarkBatchDelete1000of1000Records(b *testing.B) { func BenchmarkBatchDelete10000of10000Records(b *testing.B) { batchDeleteNofNRecords(b, 10000) -} \ No newline at end of file +} diff --git a/delete_test.go b/delete_test.go index c0a7dea..48b668c 100644 --- a/delete_test.go +++ b/delete_test.go @@ -47,7 +47,7 @@ func TestBatchDelete(t *testing.T) { func TestBoundedDelete(t *testing.T) { const ( - nilBoundValsErr = "accepted nil bound value" + nilBoundValsErr = "accepted nil bound value" generalBoundsErr = "general bounds error" ) @@ -93,4 +93,4 @@ func TestBoundedDelete(t *testing.T) { if err := verifyRecords(sm.IterCh(), false); err != nil { t.Fatal(err) } -} \ No newline at end of file +} diff --git a/desc/error.go b/desc/error.go index b65108f..491313f 100644 --- a/desc/error.go +++ b/desc/error.go @@ -1,3 +1,3 @@ package desc -const greaterThanErr = "the lesser value was greater than the higher value!" \ No newline at end of file +const greaterThanErr = "the lesser value was greater than the higher value!" diff --git a/desc/numeric.go b/desc/numeric.go index e6886b0..4429b42 100644 --- a/desc/numeric.go +++ b/desc/numeric.go @@ -46,4 +46,4 @@ func Uint(i, j interface{}) bool { func Int(i, j interface{}) bool { return i.(int) > j.(int) -} \ No newline at end of file +} diff --git a/desc/numeric_test.go b/desc/numeric_test.go index 79e46ff..cc085ae 100644 --- a/desc/numeric_test.go +++ b/desc/numeric_test.go @@ -72,4 +72,4 @@ func TestInt(t *testing.T) { if Int(int(0), 0) { t.Fatal("desc.TestInt failed: %v", greaterThanErr) } -} \ No newline at end of file +} diff --git a/desc/time.go b/desc/time.go index 8016d53..a1a8310 100644 --- a/desc/time.go +++ b/desc/time.go @@ -4,4 +4,4 @@ import "time" func Time(i, j interface{}) bool { return i.(time.Time).After(j.(time.Time)) -} \ No newline at end of file +} diff --git a/desc/time_test.go b/desc/time_test.go index 9ef7852..02d6fe6 100644 --- a/desc/time_test.go +++ b/desc/time_test.go @@ -12,4 +12,4 @@ func TestTime(t *testing.T) { if Time(earlerDate, laterDate) { t.Fatal("desc.TestTime failed: earlierDate was after laterDate") } -} \ No newline at end of file +} diff --git a/get.go b/get.go index e048726..8b8c325 100644 --- a/get.go +++ b/get.go @@ -16,4 +16,4 @@ func (sm *SortedMap) BatchGet(keys []interface{}) ([]interface{}, []bool) { } return vals, results -} \ No newline at end of file +} diff --git a/get_bench_test.go b/get_bench_test.go index 0858fc7..9b8ae7c 100644 --- a/get_bench_test.go +++ b/get_bench_test.go @@ -70,4 +70,4 @@ func BenchmarkBatchGet1000of1000Records(b *testing.B) { func BenchmarkBatchGet10000of10000Records(b *testing.B) { batchGetNofNRecords(b, 10000) -} \ No newline at end of file +} diff --git a/get_test.go b/get_test.go index 7c679d8..f9fda83 100644 --- a/get_test.go +++ b/get_test.go @@ -31,4 +31,4 @@ func TestBatchGet(t *testing.T) { if err := verifyRecords(sm.IterCh(), false); err != nil { t.Fatal(err) } -} \ No newline at end of file +} diff --git a/has.go b/has.go index 03ba2ab..58a4d97 100644 --- a/has.go +++ b/has.go @@ -13,4 +13,4 @@ func (sm *SortedMap) BatchHas(keys []interface{}) []bool { _, results[i] = sm.idx[key] } return results -} \ No newline at end of file +} diff --git a/has_bench_test.go b/has_bench_test.go index 98b7f07..b114895 100644 --- a/has_bench_test.go +++ b/has_bench_test.go @@ -70,4 +70,4 @@ func BenchmarkBatchHas1000of1000Records(b *testing.B) { func BenchmarkBatchHas10000of10000Records(b *testing.B) { batchHasNofNRecords(b, 10000) -} \ No newline at end of file +} diff --git a/has_test.go b/has_test.go index bcb491f..b598617 100644 --- a/has_test.go +++ b/has_test.go @@ -30,4 +30,4 @@ func TestBatchHas(t *testing.T) { if err := verifyRecords(sm.IterCh(), false); err != nil { t.Fatal(err) } -} \ No newline at end of file +} diff --git a/insert.go b/insert.go index d81d5d9..9a1c24f 100644 --- a/insert.go +++ b/insert.go @@ -47,7 +47,7 @@ func (sm *SortedMap) batchInsertMapStringKeys(m map[string]interface{}) error { // BatchInsertMap adds all map keys and values to the collection. // If a key already exists, the value will not be inserted and an error will be returned. -// Use BatchReplaceMap for the alternative functionality. +// Use BatchReplaceMap for the alternative functionality. func (sm *SortedMap) BatchInsertMap(v interface{}) error { const unsupportedTypeErr = "Unsupported type." @@ -61,4 +61,4 @@ func (sm *SortedMap) BatchInsertMap(v interface{}) error { default: return fmt.Errorf("%s", unsupportedTypeErr) } -} \ No newline at end of file +} diff --git a/insert_bench_test.go b/insert_bench_test.go index a821b13..39adfd2 100644 --- a/insert_bench_test.go +++ b/insert_bench_test.go @@ -54,4 +54,4 @@ func BenchmarkBatchInsert1000Records(b *testing.B) { func BenchmarkBatchInsert10000Records(b *testing.B) { batchInsertRecords(b, 10000) -} \ No newline at end of file +} diff --git a/insert_test.go b/insert_test.go index 802cc2c..e691bab 100644 --- a/insert_test.go +++ b/insert_test.go @@ -133,8 +133,8 @@ func TestBatchInsertMapWithExistingStringKeys(t *testing.T) { } } -func TestBatchInsertMapWithNilType(t *testing.T) { +func TestBatchInsertMapWithNilType(t *testing.T) { if err := New(0, asc.Time).BatchInsertMap(nil); err == nil { t.Fatal("a nil type was allowed where a supported map type is required.") } -} \ No newline at end of file +} diff --git a/insertsort.go b/insertsort.go index 0791d8c..e6e6556 100644 --- a/insertsort.go +++ b/insertsort.go @@ -6,4 +6,4 @@ func (sm *SortedMap) insertSort(key, val interface{}) []interface{} { return insertInterface(sm.sorted, key, sort.Search(len(sm.sorted), func(i int) bool { return sm.lessFn(val, sm.idx[sm.sorted[i]]) })) -} \ No newline at end of file +} diff --git a/iter.go b/iter.go index 07068ca..e0f204d 100644 --- a/iter.go +++ b/iter.go @@ -7,10 +7,10 @@ import "time" // channel send goroutines to time-out. // BufSize is set to 1 if its field is set to a lower value. // LowerBound and UpperBound default to regular iteration when left unset. -type IterChParams struct{ - Reversed bool +type IterChParams struct { + Reversed bool SendTimeout time.Duration - BufSize int + BufSize int LowerBound, UpperBound interface{} } @@ -119,7 +119,7 @@ func (sm *SortedMap) IterCh() <-chan Record { // This method defaults to the expected behavior of blocking until a channel send completes, with no timeout. func (sm *SortedMap) BoundedIterCh(reversed bool, lowerBound, upperBound interface{}) (<-chan Record, bool) { return sm.iterCh(IterChParams{ - Reversed: reversed, + Reversed: reversed, LowerBound: lowerBound, UpperBound: upperBound, }) @@ -143,4 +143,4 @@ func (sm *SortedMap) IterFunc(reversed bool, f IterCallbackFunc) { // Sort order is reversed if the reversed argument is set to true. func (sm *SortedMap) BoundedIterFunc(reversed bool, lowerBound, upperBound interface{}, f IterCallbackFunc) bool { return sm.iterFunc(reversed, lowerBound, upperBound, f) -} \ No newline at end of file +} diff --git a/iter_test.go b/iter_test.go index 0619412..f6502dd 100644 --- a/iter_test.go +++ b/iter_test.go @@ -6,14 +6,14 @@ import ( ) const ( - nilBoundValsErr = "accepted nil bound values" + nilBoundValsErr = "accepted nil bound values" generalBoundsErr = "between bounds error" - nilValErr = "nil value!" - nonNilValErr = "non-nil value" - runawayIterErr = "runaway iterator!" + nilValErr = "nil value!" + nonNilValErr = "non-nil value" + runawayIterErr = "runaway iterator!" ) -var maxTime = time.Unix(1<<63 - 62135596801, 999999999) +var maxTime = time.Unix(1<<63-62135596801, 999999999) func TestIterCh(t *testing.T) { if _, _, err := newSortedMapFromRandRecords(1000); err != nil { @@ -33,7 +33,7 @@ func TestIterChTimeout(t *testing.T) { if ch, ok := sm.CustomIterCh(params); ok { for i := 0; i < 5; i++ { time.Sleep(sleepDur) - rec := <- ch + rec := <-ch if i > 1 && rec.Key != nil { t.Fatalf("TestIterChTimeout failed: %v: %v", nonNilValErr, rec.Key) } @@ -48,7 +48,7 @@ func TestIterChTimeout(t *testing.T) { if ch, ok := sm.CustomIterCh(params); ok { for i := 0; i < 5; i++ { time.Sleep(sleepDur) - rec := <- ch + rec := <-ch if i > 1 && rec.Key != nil { t.Fatalf("TestIterChTimeout failed: %v: %v", nonNilValErr, rec.Key) } @@ -58,13 +58,13 @@ func TestIterChTimeout(t *testing.T) { } params = IterChParams{ - Reversed: true, + Reversed: true, SendTimeout: timeout, } if ch, ok := sm.CustomIterCh(params); ok { for i := 0; i < 5; i++ { time.Sleep(sleepDur) - rec := <- ch + rec := <-ch if i > 1 && rec.Key != nil { t.Fatalf("TestIterChTimeout failed: %v: %v", nonNilValErr, rec.Key) } @@ -79,7 +79,7 @@ func TestIterChTimeout(t *testing.T) { if ch, ok := sm.CustomIterCh(params); ok { for i := 0; i < 5; i++ { time.Sleep(sleepDur) - rec := <- ch + rec := <-ch if i > 1 && rec.Key != nil { t.Fatalf("TestIterChTimeout failed: %v: %v", nonNilValErr, rec.Key) } @@ -154,7 +154,7 @@ func TestBoundedIterCh(t *testing.T) { func TestCustomIterCh(t *testing.T) { const ( - nilBoundValsErr = "accepted two nil bound values" + nilBoundValsErr = "accepted two nil bound values" generalBoundsErr = "only one bound value" ) sm, _, err := newSortedMapFromRandRecords(1000) @@ -170,7 +170,7 @@ func TestCustomIterCh(t *testing.T) { params := IterChParams{ Reversed: reversed, - BufSize: buffSize, + BufSize: buffSize, } if ch, ok := sm.CustomIterCh(params); ok { @@ -182,8 +182,8 @@ func TestCustomIterCh(t *testing.T) { } params = IterChParams{ - Reversed: reversed, - BufSize: buffSize, + Reversed: reversed, + BufSize: buffSize, LowerBound: earlierDate, UpperBound: laterDate, } @@ -197,8 +197,8 @@ func TestCustomIterCh(t *testing.T) { } params = IterChParams{ - Reversed: reversed, - BufSize: buffSize, + Reversed: reversed, + BufSize: buffSize, LowerBound: laterDate, UpperBound: earlierDate, } @@ -213,8 +213,8 @@ func TestCustomIterCh(t *testing.T) { reversed = false params = IterChParams{ - Reversed: reversed, - BufSize: 0, + Reversed: reversed, + BufSize: 0, LowerBound: laterDate, UpperBound: earlierDate, } @@ -370,4 +370,4 @@ func TestBoundedIterFunc(t *testing.T) { }); ok { t.Fatalf("TestBoundedIterFunc failed: %v", nilValErr) } -} \ No newline at end of file +} diff --git a/keys.go b/keys.go index a55a600..f8de44e 100644 --- a/keys.go +++ b/keys.go @@ -5,7 +5,7 @@ func (sm *SortedMap) keys(lowerBound, upperBound interface{}) ([]interface{}, bo if idxBounds == nil { return nil, false } - return sm.sorted[idxBounds[0]:idxBounds[1] + 1], true + return sm.sorted[idxBounds[0] : idxBounds[1]+1], true } // Keys returns a slice containing sorted keys. @@ -19,4 +19,4 @@ func (sm *SortedMap) Keys() []interface{} { // The returned slice is valid until the next modification to the SortedMap structure. func (sm *SortedMap) BoundedKeys(lowerBound, upperBound interface{}) ([]interface{}, bool) { return sm.keys(lowerBound, upperBound) -} \ No newline at end of file +} diff --git a/keys_test.go b/keys_test.go index ae88c6f..aa1a815 100644 --- a/keys_test.go +++ b/keys_test.go @@ -49,7 +49,7 @@ func TestBoundedKeysWithNoBoundsReturned(t *testing.T) { if err != nil { t.Fatal(err) } - if val, ok := sm.BoundedKeys(time.Now().Add(-1 * time.Microsecond), time.Now()); ok { + if val, ok := sm.BoundedKeys(time.Now().Add(-1*time.Microsecond), time.Now()); ok { t.Fatalf("Values fall between or are equal to the given bounds when it should not have returned bounds: %+v", sm.idx[val[0]]) } -} \ No newline at end of file +} diff --git a/map.go b/map.go index 00d6aeb..7340b6d 100644 --- a/map.go +++ b/map.go @@ -6,4 +6,4 @@ package sortedmap // and iterate over them using a slice for-range loop, rather than a channel for-range loop. func (sm *SortedMap) Map() map[interface{}]interface{} { return sm.idx -} \ No newline at end of file +} diff --git a/replace.go b/replace.go index 2bad451..9b49e0c 100644 --- a/replace.go +++ b/replace.go @@ -16,7 +16,7 @@ func (sm *SortedMap) Replace(key, val interface{}) { // BatchReplace adds all given records to the collection. // Even if a key already exists, the value will be inserted. -// Use BatchInsert for the alternative functionality. +// Use BatchInsert for the alternative functionality. func (sm *SortedMap) BatchReplace(recs []Record) { for _, rec := range recs { sm.replace(rec.Key, rec.Val) @@ -37,7 +37,7 @@ func (sm *SortedMap) batchReplaceMapStringKeys(m map[string]interface{}) { // BatchReplaceMap adds all map keys and values to the collection. // Even if a key already exists, the value will be inserted. -// Use BatchInsertMap for the alternative functionality. +// Use BatchInsertMap for the alternative functionality. func (sm *SortedMap) BatchReplaceMap(v interface{}) error { const unsupportedTypeErr = "Unsupported type." @@ -53,4 +53,4 @@ func (sm *SortedMap) BatchReplaceMap(v interface{}) error { default: return fmt.Errorf("%s", unsupportedTypeErr) } -} \ No newline at end of file +} diff --git a/replace_bench_test.go b/replace_bench_test.go index 9540763..1af5360 100644 --- a/replace_bench_test.go +++ b/replace_bench_test.go @@ -74,4 +74,4 @@ func BenchmarkBatchReplace1000of1000Records(b *testing.B) { func BenchmarkBatchReplace10000of10000Records(b *testing.B) { batchReplaceNofNRecords(b, 10000) -} \ No newline at end of file +} diff --git a/replace_test.go b/replace_test.go index e87d2de..9d005f7 100644 --- a/replace_test.go +++ b/replace_test.go @@ -69,4 +69,4 @@ func TestBatchReplaceMapWithNilType(t *testing.T) { if err := New(0, asc.Time).BatchReplaceMap(nil); err == nil { t.Fatal("a nil type was allowed where a supported map type is required.") } -} \ No newline at end of file +} diff --git a/sliceutils.go b/sliceutils.go index ef28d12..fb6e248 100644 --- a/sliceutils.go +++ b/sliceutils.go @@ -4,7 +4,7 @@ package sortedmap // and then returns an updated reference. func insertInterface(s []interface{}, v interface{}, i int) []interface{} { s = append(s, nil) - copy(s[i + 1:], s[i:]) + copy(s[i+1:], s[i:]) s[i] = v return s @@ -13,8 +13,8 @@ func insertInterface(s []interface{}, v interface{}, i int) []interface{} { // deleteInterface deletes an interface{} value from slice s, at index i, // and then returns an updated reference. func deleteInterface(s []interface{}, i int) []interface{} { - copy(s[i:], s[i + 1:]) - s[len(s) - 1] = nil + copy(s[i:], s[i+1:]) + s[len(s)-1] = nil - return s[:len(s) - 1] -} \ No newline at end of file + return s[:len(s)-1] +} diff --git a/sortedmap.go b/sortedmap.go index 4f28935..725ff79 100644 --- a/sortedmap.go +++ b/sortedmap.go @@ -41,4 +41,4 @@ func New(n int, lessFn SortLessFunc) *SortedMap { // Len returns the number of items in the collection. func (sm *SortedMap) Len() int { return len(sm.sorted) -} \ No newline at end of file +} diff --git a/sortedmap_bench_test.go b/sortedmap_bench_test.go index f7f61ef..cef0b0e 100644 --- a/sortedmap_bench_test.go +++ b/sortedmap_bench_test.go @@ -8,10 +8,11 @@ import ( func BenchmarkNew(b *testing.B) { var sm *SortedMap - if sm == nil {} + if sm == nil { + } b.ResetTimer() for i := 0; i < b.N; i++ { sm = New(0, asc.Time) } -} \ No newline at end of file +} diff --git a/sortedmap_test.go b/sortedmap_test.go index 3ab7aba..3da87ab 100644 --- a/sortedmap_test.go +++ b/sortedmap_test.go @@ -38,4 +38,4 @@ func TestLen(t *testing.T) { if sm.Len() != count { t.Fatalf("TestLen failed: invalid SortedMap length. Expected: %v, Had: %v.", count, sm.Len()) } -} \ No newline at end of file +} diff --git a/testing_utils_test.go b/testing_utils_test.go index 0dae059..9941129 100644 --- a/testing_utils_test.go +++ b/testing_utils_test.go @@ -2,8 +2,8 @@ package sortedmap import ( "fmt" - "time" mrand "math/rand" + "time" "github.com/umpc/go-sortedmap/asc" ) @@ -96,4 +96,4 @@ func newRandSortedMapWithKeys(n int) (*SortedMap, []Record, []interface{}, error keys[n] = rec.Key } return sm, records, keys, err -} \ No newline at end of file +}