forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routing_map.go
32 lines (27 loc) · 831 Bytes
/
routing_map.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2014, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package engine
type routingMap map[string][]interface{}
func (rtm routingMap) Add(shard string, id interface{}) {
rtm[shard] = append(rtm[shard], id)
}
func (rtm routingMap) Shards() []string {
shards := make([]string, 0, len(rtm))
for k := range rtm {
shards = append(shards, k)
}
return shards
}
func (rtm routingMap) ShardVars(bv map[string]interface{}) map[string]map[string]interface{} {
shardVars := make(map[string]map[string]interface{}, len(rtm))
for shard, vals := range rtm {
newbv := make(map[string]interface{}, len(bv)+1)
for k, v := range bv {
newbv[k] = v
}
newbv[ListVarName] = vals
shardVars[shard] = newbv
}
return shardVars
}