本文整理汇总了Golang中github.com/couchbaselabs/sync_gateway/base.Set类的典型用法代码示例。如果您正苦于以下问题:Golang Set类的具体用法?Golang Set怎么用?Golang Set使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Set类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateChannels
// Updates the Channels property of a document object with current & past channels.
// Returns the set of channels that have changed (document joined or left in this revision)
func (doc *document) updateChannels(newChannels base.Set) (changedChannels base.Set) {
var changed []string
oldChannels := doc.Channels
if oldChannels == nil {
oldChannels = ChannelMap{}
doc.Channels = oldChannels
} else {
// Mark every no-longer-current channel as unsubscribed:
curSequence := doc.Sequence
for channel, removal := range oldChannels {
if removal == nil && !newChannels.Contains(channel) {
oldChannels[channel] = &ChannelRemoval{
Seq: curSequence,
RevID: doc.CurrentRev,
Deleted: doc.Deleted}
changed = append(changed, channel)
}
}
}
// Mark every current channel as subscribed:
for channel, _ := range newChannels {
if value, exists := oldChannels[channel]; value != nil || !exists {
oldChannels[channel] = nil
changed = append(changed, channel)
}
}
if changed != nil {
base.LogTo("CRUD", "\tDoc %q in channels %q", doc.ID, newChannels)
changedChannels = channels.SetOf(changed...)
}
return
}
示例2: UpdateAtSequence
// Updates membership to match the given Set. Newly added members will have the given sequence.
func (set TimedSet) UpdateAtSequence(other base.Set, sequence uint64) bool {
changed := false
for name, _ := range set {
if !other.Contains(name) {
delete(set, name)
changed = true
}
}
for name, _ := range other {
if !set.Contains(name) {
set[name] = sequence
changed = true
}
}
return changed
}
示例3: _addPendingLogs
// Add the first change(s) from pendingLogs if they're the next sequence or have been waiting too
// long, or if there are simply too many pending entries.
// Returns the channels that changed.
func (c *changeCache) _addPendingLogs() base.Set {
var changedChannels base.Set
for len(c.pendingLogs) > 0 {
change := c.pendingLogs[0]
isNext := change.Sequence == c.nextSequence
if isNext || len(c.pendingLogs) > MaxChannelLogPendingCount || time.Since(c.pendingLogs[0].TimeReceived) >= MaxChannelLogPendingWaitTime {
if !isNext {
base.Warn("changeCache: Giving up, accepting #%d even though #%d is missing",
change.Sequence, c.nextSequence)
changeCacheExpvars.Add("outOfOrder", 1)
}
heap.Pop(&c.pendingLogs)
changedChannels = changedChannels.Union(c._addToCache(change))
} else {
break
}
}
return changedChannels
}
示例4: processEntry
// Handles a newly-arrived LogEntry.
func (c *changeCache) processEntry(change *LogEntry) base.Set {
c.lock.Lock()
defer c.lock.Unlock()
if c.logsDisabled {
return nil
}
sequence := change.Sequence
nextSequence := c.nextSequence
if _, found := c.receivedSeqs[sequence]; found {
base.LogTo("Cache+", " Ignoring duplicate of #%d", sequence)
return nil
}
c.receivedSeqs[sequence] = struct{}{}
// FIX: c.receivedSeqs grows monotonically. Need a way to remove old sequences.
var changedChannels base.Set
if sequence == nextSequence || nextSequence == 0 {
// This is the expected next sequence so we can add it now:
changedChannels = c._addToCache(change)
// Also add any pending sequences that are now contiguous:
changedChannels = changedChannels.Union(c._addPendingLogs())
} else if sequence > nextSequence {
// There's a missing sequence (or several), so put this one on ice until it arrives:
heap.Push(&c.pendingLogs, change)
numPending := len(c.pendingLogs)
base.LogTo("Cache", " Deferring #%d (%d now waiting for #%d...#%d)",
sequence, numPending, nextSequence, c.pendingLogs[0].Sequence-1)
changeCacheExpvars.Get("maxPending").(*base.IntMax).SetIfMax(int64(numPending))
if numPending > MaxChannelLogPendingCount {
// Too many pending; add the oldest one:
changedChannels = c._addPendingLogs()
}
} else if sequence > c.initialSequence {
// Out-of-order sequence received!
base.Warn(" Received out-of-order change (seq %d, expecting %d) doc %q / %q", sequence, nextSequence, change.DocID, change.RevID)
changedChannels = c._addToCache(change)
}
return changedChannels
}
示例5: IgnoringStar
// Returns a set with any "*" channel removed.
func IgnoringStar(set base.Set) base.Set {
return set.Removing("*")
}
示例6: ExpandWildCardChannel
// If a channel list contains a wildcard ("*"), replace it with all the user's accessible channels.
func (user *userImpl) ExpandWildCardChannel(channels base.Set) base.Set {
if channels.Contains("*") {
channels = user.InheritedChannels().AsSet()
}
return channels
}