From 53ceb4ee2eb19b35822348b1c9a68a5ea3d6c7d9 Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Tue, 12 Jul 2016 22:59:36 -0600 Subject: [PATCH] removed ScanType --- controller/aofshrink.go | 2 +- controller/collection/collection.go | 33 ++++++----------------------- controller/crud.go | 2 +- controller/scan.go | 8 +++---- controller/search.go | 8 +++---- controller/stats.go | 7 +++--- 6 files changed, 18 insertions(+), 42 deletions(-) diff --git a/controller/aofshrink.go b/controller/aofshrink.go index 692696cd..66d91cbb 100644 --- a/controller/aofshrink.go +++ b/controller/aofshrink.go @@ -150,7 +150,7 @@ func (c *Controller) aofshrink() { objs := make(map[string]objFields) c.mu.Lock() fnames := col.FieldArr() // reload an array of field names to match each object - col.ScanGreaterOrEqual(nextID, 1, collection.TypeAll, false, + col.ScanGreaterOrEqual(nextID, 1, false, func(id string, obj geojson.Object, fields []float64) bool { if id != nextID { objs[id] = objFields{obj, fields} diff --git a/controller/collection/collection.go b/controller/collection/collection.go index 257d2a6c..067c999f 100644 --- a/controller/collection/collection.go +++ b/controller/collection/collection.go @@ -6,18 +6,6 @@ import ( "github.com/tidwall/tile38/index" ) -// ScanType is the classification of objects that are returned from Scan() -type ScanType int - -const ( - // TypeAll means to return all type during a Scan() - TypeAll = ScanType(0) - // TypeGeometry means to return only geometries - TypeGeometry = ScanType(1) - // TypeNonGeometry means to return non-geometries - TypeNonGeometry = ScanType(2) -) - const ( idOrdered = 0 valueOrdered = 1 @@ -84,15 +72,8 @@ func New() *Collection { } // Count returns the number of objects in collection. -func (c *Collection) Count(stype ScanType) int { - switch stype { - default: - return c.objects + c.nobjects - case TypeGeometry: - return c.objects - case TypeNonGeometry: - return c.nobjects - } +func (c *Collection) Count() int { + return c.objects + c.nobjects } // PointCount returns the number of points (lat/lon coordinates) in collection. @@ -236,7 +217,7 @@ func (c *Collection) FieldArr() []string { } // Scan iterates though the collection ids. A cursor can be used for paging. -func (c *Collection) Scan(cursor uint64, stype ScanType, desc bool, +func (c *Collection) Scan(cursor uint64, desc bool, iterator func(id string, obj geojson.Object, fields []float64) bool, ) (ncursor uint64) { var i uint64 @@ -258,7 +239,7 @@ func (c *Collection) Scan(cursor uint64, stype ScanType, desc bool, } // ScanGreaterOrEqual iterates though the collection starting with specified id. A cursor can be used for paging. -func (c *Collection) ScanRange(cursor uint64, stype ScanType, start, end string, desc bool, +func (c *Collection) ScanRange(cursor uint64, start, end string, desc bool, iterator func(id string, obj geojson.Object, fields []float64) bool, ) (ncursor uint64) { var i uint64 @@ -281,7 +262,7 @@ func (c *Collection) ScanRange(cursor uint64, stype ScanType, start, end string, } // SearchValues iterates though the collection values. A cursor can be used for paging. -func (c *Collection) SearchValues(cursor uint64, stype ScanType, desc bool, +func (c *Collection) SearchValues(cursor uint64, desc bool, iterator func(id string, obj geojson.Object, fields []float64) bool, ) (ncursor uint64) { var i uint64 @@ -303,7 +284,7 @@ func (c *Collection) SearchValues(cursor uint64, stype ScanType, desc bool, } // SearchValuesRange iterates though the collection values. A cursor can be used for paging. -func (c *Collection) SearchValuesRange(cursor uint64, stype ScanType, start, end string, desc bool, +func (c *Collection) SearchValuesRange(cursor uint64, start, end string, desc bool, iterator func(id string, obj geojson.Object, fields []float64) bool, ) (ncursor uint64) { var i uint64 @@ -325,7 +306,7 @@ func (c *Collection) SearchValuesRange(cursor uint64, stype ScanType, start, end } // ScanGreaterOrEqual iterates though the collection starting with specified id. A cursor can be used for paging. -func (c *Collection) ScanGreaterOrEqual(id string, cursor uint64, stype ScanType, desc bool, +func (c *Collection) ScanGreaterOrEqual(id string, cursor uint64, desc bool, iterator func(id string, obj geojson.Object, fields []float64) bool, ) (ncursor uint64) { var i uint64 diff --git a/controller/crud.go b/controller/crud.go index e57a96ed..28349593 100644 --- a/controller/crud.go +++ b/controller/crud.go @@ -229,7 +229,7 @@ func (c *Controller) cmdDel(msg *server.Message) (res string, d commandDetailsT, if col != nil { d.obj, d.fields, ok = col.Remove(d.id) if ok { - if col.Count(collection.TypeAll) == 0 { + if col.Count() == 0 { c.deleteCol(d.key) d.revert = func() { c.setCol(d.key, col) diff --git a/controller/scan.go b/controller/scan.go index d078c709..1ef61aff 100644 --- a/controller/scan.go +++ b/controller/scan.go @@ -5,7 +5,6 @@ import ( "time" "github.com/tidwall/resp" - "github.com/tidwall/tile38/controller/collection" "github.com/tidwall/tile38/controller/glob" "github.com/tidwall/tile38/controller/server" "github.com/tidwall/tile38/geojson" @@ -40,9 +39,8 @@ func (c *Controller) cmdScan(msg *server.Message) (res string, err error) { } sw.writeHead() if sw.col != nil { - stype := collection.TypeAll if sw.output == outputCount && len(sw.wheres) == 0 && sw.globEverything == true { - count := sw.col.Count(stype) - int(s.cursor) + count := sw.col.Count() - int(s.cursor) if count < 0 { count = 0 } @@ -50,14 +48,14 @@ func (c *Controller) cmdScan(msg *server.Message) (res string, err error) { } else { g := glob.Parse(sw.globPattern, s.desc) if g.Limits[0] == "" && g.Limits[1] == "" { - s.cursor = sw.col.Scan(s.cursor, stype, s.desc, + s.cursor = sw.col.Scan(s.cursor, s.desc, func(id string, o geojson.Object, fields []float64) bool { return sw.writeObject(id, o, fields, false) }, ) } else { s.cursor = sw.col.ScanRange( - s.cursor, stype, g.Limits[0], g.Limits[1], s.desc, + s.cursor, g.Limits[0], g.Limits[1], s.desc, func(id string, o geojson.Object, fields []float64) bool { return sw.writeObject(id, o, fields, false) }, diff --git a/controller/search.go b/controller/search.go index 91992dbd..8e8542f6 100644 --- a/controller/search.go +++ b/controller/search.go @@ -8,7 +8,6 @@ import ( "github.com/tidwall/resp" "github.com/tidwall/tile38/controller/bing" - "github.com/tidwall/tile38/controller/collection" "github.com/tidwall/tile38/controller/glob" "github.com/tidwall/tile38/controller/server" "github.com/tidwall/tile38/geojson" @@ -366,9 +365,8 @@ func (c *Controller) cmdSearch(msg *server.Message) (res string, err error) { } sw.writeHead() if sw.col != nil { - stype := collection.TypeAll if sw.output == outputCount && len(sw.wheres) == 0 && sw.globEverything == true { - count := sw.col.Count(stype) - int(s.cursor) + count := sw.col.Count() - int(s.cursor) if count < 0 { count = 0 } @@ -376,14 +374,14 @@ func (c *Controller) cmdSearch(msg *server.Message) (res string, err error) { } else { g := glob.Parse(sw.globPattern, s.desc) if g.Limits[0] == "" && g.Limits[1] == "" { - s.cursor = sw.col.SearchValues(s.cursor, stype, s.desc, + s.cursor = sw.col.SearchValues(s.cursor, s.desc, func(id string, o geojson.Object, fields []float64) bool { return sw.writeObject(id, o, fields, false) }, ) } else { s.cursor = sw.col.SearchValuesRange( - s.cursor, stype, g.Limits[0], g.Limits[1], s.desc, + s.cursor, g.Limits[0], g.Limits[1], s.desc, func(id string, o geojson.Object, fields []float64) bool { return sw.writeObject(id, o, fields, false) }, diff --git a/controller/stats.go b/controller/stats.go index 5b34ceba..c2d8f33c 100644 --- a/controller/stats.go +++ b/controller/stats.go @@ -9,7 +9,6 @@ import ( "github.com/tidwall/btree" "github.com/tidwall/resp" - "github.com/tidwall/tile38/controller/collection" "github.com/tidwall/tile38/controller/server" ) @@ -34,7 +33,7 @@ func (c *Controller) cmdStats(msg *server.Message) (res string, err error) { points := col.PointCount() m["num_points"] = points m["in_memory_size"] = col.TotalWeight() - m["num_objects"] = col.Count(collection.TypeAll) + m["num_objects"] = col.Count() switch msg.OutputType { case server.JSON: ms = append(ms, m) @@ -93,7 +92,7 @@ func (c *Controller) cmdServer(msg *server.Message) (res string, err error) { c.cols.Ascend(func(item btree.Item) bool { col := item.(*collectionT).Collection points += col.PointCount() - objects += col.Count(collection.TypeAll) + objects += col.Count() return true }) m["num_points"] = points @@ -156,7 +155,7 @@ func (c *Controller) statsCollections(line string) (string, error) { points := col.PointCount() m["num_points"] = points m["in_memory_size"] = col.TotalWeight() - m["num_objects"] = col.Count(collection.TypeAll) + m["num_objects"] = col.Count() ms = append(ms, m) } else { ms = append(ms, nil)