Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1861)

Unified Diff: appengine/cmd/dm/distributor/impl/jobsim/parser/range_slice.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: work in progress Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/cmd/dm/distributor/impl/jobsim/parser/range_slice.go
diff --git a/appengine/cmd/dm/distributor/impl/jobsim/parser/range_slice.go b/appengine/cmd/dm/distributor/impl/jobsim/parser/range_slice.go
new file mode 100644
index 0000000000000000000000000000000000000000..728ec619667349c9a0dc88cd54729a7ac41dcbdb
--- /dev/null
+++ b/appengine/cmd/dm/distributor/impl/jobsim/parser/range_slice.go
@@ -0,0 +1,62 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package parser
+
+import (
+ "bytes"
+ "fmt"
+)
+
+type Range [2]uint64
+
+func (r Range) Low() uint64 { return r[0] }
+func (r Range) Single() (uint64, bool) { return r[0], r[1] == 0 }
+func (r Range) High() uint64 {
+ if r[1] == 0 {
+ return r[0]
+ }
+ return r[1]
+}
+
+func (r Range) Iter(cb func(uint64) error) error {
+ if s, ok := r.Single(); ok {
+ return cb(s)
+ }
+ for i := r.Low(); i < r.High(); i++ {
+ if err := cb(i); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func (r Range) String() string {
+ if s, ok := r.Single(); ok {
+ return fmt.Sprintf("%d", s)
+ }
+ return fmt.Sprintf("%d-%d", r.Low(), r.High())
+}
+
+type RangeSlice []Range
+
+func (rs RangeSlice) String() string {
+ b := bytes.Buffer{}
+ for i, r := range rs {
+ if i != 0 {
+ b.WriteRune(',')
+ }
+ b.WriteString(r.String())
+ }
+ return b.String()
+}
+
+func (rs RangeSlice) Iter(cb func(uint64) error) error {
+ for _, rng := range rs {
+ if err := rng.Iter(cb); err != nil {
+ return err
+ }
+ }
+ return nil
+}

Powered by Google App Engine
This is Rietveld 408576698