+ nameMatches := func(name []byte) bool {
+ for _, r := range regexes {
+ if r.Match(name) {
+ return true
+ }
+ }
+ return false
+ }
+ return sc.listIndexesFunc(nameMatches)
+}
+
+// listIndexesFunc lists stats indexes. The optional function
+// argument filters returned values or returns all if empty
+func (sc *StatsClient) listIndexesFunc(f func(name []byte) bool) (indexes []uint32, err error) {
+ if f == nil {
+ // there is around ~3157 stats, so to avoid too many allocations
+ // we set capacity to 3200 when listing all stats
+ indexes = make([]uint32, 0, 3200)
+ }
+
+ dirVector := sc.GetDirectoryVector()
+ if dirVector == nil {
+ return nil, err
+ }
+ vecLen := *(*uint32)(vectorLen(dirVector))
+
+ for i := uint32(0); i < vecLen; i++ {
+ _, dirName, _ := sc.GetStatDirOnIndex(dirVector, i)
+ if f != nil {
+ if len(dirName) == 0 || !f(dirName) {
+ continue
+ }
+ }
+ indexes = append(indexes, i)
+ }
+
+ return indexes, nil