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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package parser
6
7 import (
8 "bytes"
9 "fmt"
10 )
11
12 type Range [2]uint64
13
14 func (r Range) Low() uint64 { return r[0] }
15 func (r Range) Single() (uint64, bool) { return r[0], r[1] == 0 }
16 func (r Range) High() uint64 {
17 if r[1] == 0 {
18 return r[0]
19 }
20 return r[1]
21 }
22
23 func (r Range) Iter(cb func(uint64) error) error {
24 if s, ok := r.Single(); ok {
25 return cb(s)
26 }
27 for i := r.Low(); i < r.High(); i++ {
28 if err := cb(i); err != nil {
29 return err
30 }
31 }
32 return nil
33 }
34
35 func (r Range) String() string {
36 if s, ok := r.Single(); ok {
37 return fmt.Sprintf("%d", s)
38 }
39 return fmt.Sprintf("%d-%d", r.Low(), r.High())
40 }
41
42 type RangeSlice []Range
43
44 func (rs RangeSlice) String() string {
45 b := bytes.Buffer{}
46 for i, r := range rs {
47 if i != 0 {
48 b.WriteRune(',')
49 }
50 b.WriteString(r.String())
51 }
52 return b.String()
53 }
54
55 func (rs RangeSlice) Iter(cb func(uint64) error) error {
56 for _, rng := range rs {
57 if err := rng.Iter(cb); err != nil {
58 return err
59 }
60 }
61 return nil
62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698