mirror of https://github.com/tidwall/tile38.git
removed ScanType
This commit is contained in:
parent
4656c4c8f3
commit
53ceb4ee2e
|
@ -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}
|
||||
|
|
|
@ -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:
|
||||
func (c *Collection) Count() int {
|
||||
return c.objects + c.nobjects
|
||||
case TypeGeometry:
|
||||
return c.objects
|
||||
case TypeNonGeometry:
|
||||
return 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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue