// filterByTerminal filters out terminal allocs
197385
func filterByTerminal(untainted allocSet) (nonTerminal allocSet) {
	nonTerminal = make(map[string]*structs.Allocation)
	for id, alloc := range untainted {
		if !alloc.TerminalStatus() {
			nonTerminal[id] = alloc
		}
	}
	return
}
959679
func (fm *filterManager) FilterByIndex(index int) Filter {
	fm.fmLocker.RLock()
	defer fm.fmLocker.RUnlock()
	n := len(fm.filters)
	if index < 0 && index >= n {
		return nil
	}
	return fm.filters[index]
}
683203
func (api *SIMAPI) FilterMultiBy(key string, value interface{}) *SIMAPI {
	api.filterBy(key, value, true)
	return api
}
4161
func FilterByType(msgs []chat1.MessageUnboxed, query *chat1.GetThreadQuery, includeAllErrors bool) (res []chat1.MessageUnboxed) {
	useTypeFilter := (query != nil && len(query.MessageTypes) > 0)

	typmap := make(map[chat1.MessageType]bool)
	if useTypeFilter {
		for _, mt := range query.MessageTypes {
			typmap[mt] = true
		}
	}

	for _, msg := range msgs {
		state, err := msg.State()
		if err != nil {
			if includeAllErrors {
				res = append(res, msg)
			}
			continue
		}
		switch state {
		case chat1.MessageUnboxedState_ERROR:
			if includeAllErrors {
				res = append(res, msg)
			}
		case chat1.MessageUnboxedState_PLACEHOLDER:
			// We don't know what the type is for these, so just include them
			res = append(res, msg)
		default:
			_, match := typmap[msg.GetMessageType()]
			if !useTypeFilter || match {
				res = append(res, msg)
			}
		}
	}
	return res
}
927516
func (api *RegionAPI) FilterBy(key string, value interface{}) *RegionAPI {
	api.filterBy(key, value, false)
	return api
}
884883
func (api *ProductPrivateHostAPI) FilterMultiBy(key string, value interface{}) *ProductPrivateHostAPI {
	api.filterBy(key, value, true)
	return api
}
822699
func (api *IPAddressAPI) FilterBy(key string, value interface{}) *IPAddressAPI {
	api.filterBy(key, value, false)
	return api
}
898754
func (api *ProductDiskAPI) FilterBy(key string, value interface{}) *ProductDiskAPI {
	api.filterBy(key, value, false)
	return api
}
1000575
func (api *DiskAPI) FilterBy(key string, value interface{}) *DiskAPI {
	api.filterBy(key, value, false)
	return api
}
436760
func (api *LoadBalancerAPI) FilterBy(key string, value interface{}) *LoadBalancerAPI {
	api.filterBy(key, value, false)
	return api
}
45307
func (api *SimpleMonitorAPI) FilterMultiBy(key string, value interface{}) *SimpleMonitorAPI {
	api.filterBy(key, value, true)
	return api
}
704930
func (api *AutoBackupAPI) FilterMultiBy(key string, value interface{}) *AutoBackupAPI {
	api.filterBy(key, value, true)
	return api
}
283815
func FilterTerminalAllocs(allocs []*Allocation) ([]*Allocation, map[string]*Allocation) {
	terminalAllocsByName := make(map[string]*Allocation)
	n := len(allocs)
	for i := 0; i < n; i++ {
		if allocs[i].TerminalStatus() {

			// Add the allocation to the terminal allocs map if it's not already
			// added or has a higher create index than the one which is
			// currently present.
			alloc, ok := terminalAllocsByName[allocs[i].Name]
			if !ok || alloc.CreateIndex < allocs[i].CreateIndex {
				terminalAllocsByName[allocs[i].Name] = allocs[i]
			}

			// Remove the allocation
			allocs[i], allocs[n-1] = allocs[n-1], nil
			i--
			n--
		}
	}
	return allocs[:n], terminalAllocsByName
}
985707
func (api *RegionAPI) FilterMultiBy(key string, value interface{}) *RegionAPI {
	api.filterBy(key, value, true)
	return api
}
837339
func (api *ZoneAPI) FilterBy(key string, value interface{}) *ZoneAPI {
	api.filterBy(key, value, false)
	return api
}
400180
func (api *IPv6AddrAPI) FilterBy(key string, value interface{}) *IPv6AddrAPI {
	api.filterBy(key, value, false)
	return api
}
346765
func (api *NFSAPI) FilterBy(key string, value interface{}) *NFSAPI {
	api.filterBy(key, value, false)
	return api
}