// DecompileFilter converts a packet representation of a filter into a string representation
779563
func DecompileFilter(packet *ber.Packet) (ret string, err error) {
	defer func() {
		if r := recover(); r != nil {
			err = NewError(ErrorFilterDecompile, errors.New("ldap: error decompiling filter"))
		}
	}()
	ret = "("
	err = nil
	childStr := ""

	switch packet.Tag {
	case FilterAnd:
		ret += "&"
		for _, child := range packet.Children {
			childStr, err = DecompileFilter(child)
			if err != nil {
				return
			}
			ret += childStr
		}
	case FilterOr:
		ret += "|"
		for _, child := range packet.Children {
			childStr, err = DecompileFilter(child)
			if err != nil {
				return
			}
			ret += childStr
		}
	case FilterNot:
		ret += "!"
		childStr, err = DecompileFilter(packet.Children[0])
		if err != nil {
			return
		}
		ret += childStr

	case FilterSubstrings:
		ret += ber.DecodeString(packet.Children[0].Data.Bytes())
		ret += "="
		for i, child := range packet.Children[1].Children {
			if i == 0 && child.Tag != FilterSubstringsInitial {
				ret += "*"
			}
			ret += EscapeFilter(ber.DecodeString(child.Data.Bytes()))
			if child.Tag != FilterSubstringsFinal {
				ret += "*"
			}
		}
	case FilterEqualityMatch:
		ret += ber.DecodeString(packet.Children[0].Data.Bytes())
		ret += "="
		ret += EscapeFilter(ber.DecodeString(packet.Children[1].Data.Bytes()))
	case FilterGreaterOrEqual:
		ret += ber.DecodeString(packet.Children[0].Data.Bytes())
		ret += ">="
		ret += EscapeFilter(ber.DecodeString(packet.Children[1].Data.Bytes()))
	case FilterLessOrEqual:
		ret += ber.DecodeString(packet.Children[0].Data.Bytes())
		ret += "<="
		ret += EscapeFilter(ber.DecodeString(packet.Children[1].Data.Bytes()))
	case FilterPresent:
		ret += ber.DecodeString(packet.Data.Bytes())
		ret += "=*"
	case FilterApproxMatch:
		ret += ber.DecodeString(packet.Children[0].Data.Bytes())
		ret += "~="
		ret += EscapeFilter(ber.DecodeString(packet.Children[1].Data.Bytes()))
	case FilterExtensibleMatch:
		attr := ""
		dnAttributes := false
		matchingRule := ""
		value := ""

		for _, child := range packet.Children {
			switch child.Tag {
			case MatchingRuleAssertionMatchingRule:
				matchingRule = ber.DecodeString(child.Data.Bytes())
			case MatchingRuleAssertionType:
				attr = ber.DecodeString(child.Data.Bytes())
			case MatchingRuleAssertionMatchValue:
				value = ber.DecodeString(child.Data.Bytes())
			case MatchingRuleAssertionDNAttributes:
				dnAttributes = child.Value.(bool)
			}
		}

		if len(attr) > 0 {
			ret += attr
		}
		if dnAttributes {
			ret += ":dn"
		}
		if len(matchingRule) > 0 {
			ret += ":"
			ret += matchingRule
		}
		ret += ":="
		ret += EscapeFilter(value)
	}

	ret += ")"
	return
}
2727
func (self *StandardFilterer) RemoveFilter(filter Filter) {
	if self.filters.SetContains(filter) {
		self.filters.SetRemove(filter)
	}
}
302548
func ParaFilter(content string) string {
	paragraphs := paraPattern.Split(content, -1)
	return fmt.Sprintf("<para>%s</para>", strings.Join(paragraphs, "</para><para>"))
}
188457
func NewPacketFilter(conn net.PacketConn) *PacketFilter {
	d := &PacketFilter{
		PacketConn: conn,
	}
	return d
}
663114
func (f *synthesisFilter) filter(x []float32) {
	// Shifting
	copy(f[64:], f[0:960])

	// Matrixing can be carried out efficiently using the discrete cosine
	// transform. For details, see:
	//
	//   K. Konstantinides, "Fast Subband Filtering in MPEG Audio Coding",
	//   IEEE Signal Processing Letters, Vol. 1, N. 2, pp. 26-28, Feb. 1994
	//
	dct32(x)
	for i := 0; i <= 15; i++ {
		f[i] = x[i+16]
		f[32-i] = -f[i]
	}
	f[16] = 0 // :)
	for i := 1; i <= 15; i++ {
		f[48-i] = -x[i]
		f[48+i] = -x[i]
	}
	f[48] = -x[0]

	// Windowing, etc. This is basically the same as the flow chart in the
	// standard, but with unnecessary copying eliminated.
	for j := 0; j < 32; j++ {
		var y float32
		fp, wp := j, j
		for fp < 1024 {
			y += f[fp] * synthesisWindow[wp]
			y += f[fp+96] * synthesisWindow[wp+32]
			fp += 128
			wp += 64
		}
		x[j] = y
	}
}
778910
func Filter(payloads []FullPayloadInfo, predicates ...PayloadPredicate) []FullPayloadInfo {
	var results []FullPayloadInfo
	for _, payload := range payloads {
		if matched := filterOne(payload, predicates); matched {
			results = append(results, payload)
		}
	}
	return results
}
875085
func (s *StableBloomFilter) GobDecode(data []byte) error {
	buf := bytes.NewBuffer(data)
	_, err := s.ReadFrom(buf)
	return err
}
1052735
func (d *Decoder) filter() {
	tok := d.next()
	if tok.t == tokenIdent && tok.value == "zoom" {
		compOp := d.comp()
		tok = d.next()
		if tok.t != tokenNumber {
			d.error(d.pos(tok), "zoom requires num, got %v", tok)
		}
		level, err := strconv.ParseInt(tok.value, 10, 64)
		if err != nil {
			d.error(d.pos(tok), "invalid zoom level %v: %v", tok, err)
		}
		if compOp == REGEX {
			d.error(d.pos(tok), "regular expressions are not allowed for zoom levels")
		}
		d.mss.addZoom(compOp, level)
		d.expect(tokenRBracket)
		return
	}

	var field string
	switch tok.t {
	case tokenString:
		field = tok.value[1 : len(tok.value)-1]
	case tokenIdent:
		field = tok.value
	default:
		d.error(d.pos(tok), "expected zoom or field name in filter, got '%s'", tok.value)
	}

	compOp := d.comp()
	tok = d.next()
	var value interface{}
	switch tok.t {
	case tokenString:
		value = tok.value[1 : len(tok.value)-1]
	case tokenNumber:
		value, _ = strconv.ParseFloat(tok.value, 64)
	case tokenIdent:
		if tok.value == "null" {
			value = nil
		} else {
			d.error(d.pos(tok), "unexpected value in filter '%s'", tok.value)
		}
	default:
		d.error(d.pos(tok), "unexpected value in filter '%s'", tok.value)
	}
	d.expect(tokenRBracket)
	d.mss.addFilter(field, compOp, value)
}
598948
func ConnDuplicateIPFilter() ConnFilterFunc {
	return func(cs ConnSet, c net.Conn, ips []net.IP) error {
		for _, ip := range ips {
			if cs.HasIP(ip) {
				return ErrRejected{
					conn:        c,
					err:         fmt.Errorf("IP<%v> already connected", ip),
					isDuplicate: true,
				}
			}
		}

		return nil
	}
}
669640
func (opts *Options) SetCompactionFilter(value CompactionFilter) {
	if nc, ok := value.(nativeCompactionFilter); ok {
		opts.ccf = nc.c
	} else {
		idx := registerCompactionFilter(value)
		opts.ccf = C.gorocksdb_compactionfilter_create(C.uintptr_t(idx))
	}
	C.rocksdb_options_set_compaction_filter(opts.c, opts.ccf)
}
1219594
func Decompress(encoding string, r io.Reader) (io.ReadCloser, error) {
	switch encoding {
	case "gzip":
		return gzip.NewReader(r)
	case "deflate", "zlib":
		// compatible for RFC 1950 zlib, RFC 1951 deflate, http://www.open-open.com/lib/view/open1460866410410.html
		return zlib.NewReader(r)
	default:
		return nil, ErrUnsupportedMediaType.WithMsgf("Unsupported Content-Encoding: %s", encoding)
	}
}
216364
func DecompressContent(content []byte) ([]byte, error) {

	buf := bytes.NewReader(content)
	gZipReader, _ := gzip.NewReader(buf)
	defer close(gZipReader)
	return ioutil.ReadAll(gZipReader)
}
990840
func (w *gzipResponseWriter) applyFilter() {
	if !w.filtered {
		if w.dogzip = w.filterFn(w, w.r); w.dogzip {
			setGzipHeaders(w.Header())
		}
		w.filtered = true
	}
}
224724
func NoBrFilter(content string) string {
	normalized := strings.Replace(content, "\r\n", "\n", -1)
	paragraphs := multiNewlinePattern.Split(normalized, -1)
	for i, p := range paragraphs {
		withoutCR := strings.Replace(p, "\r", " ", -1)
		withoutLF := strings.Replace(withoutCR, "\n", " ", -1)
		paragraphs[i] = spacePattern.ReplaceAllString(withoutLF, " ")
	}
	return strings.Join(paragraphs, "\n\n")
}
1351952
func PFilter(content string) template.HTML {
	paragraphs := paraPattern.Split(content, -1)
	return template.HTML(fmt.Sprintf("<p>%s</p>", strings.Join(paragraphs, "</p><p>")))
}
1132023
func decompressPings(maps []map[string]int64) ([]int64, error) {
	if len(maps) == 0 {
		return nil, nil
	}
	// First step, merge all value structures together.
	// Every ping has a bit field in an int64. However, bitwise-or preserves
	// everything that was ever alive without having to decode them multiple times.
	baseToBits := make(map[string]int64, len(maps[0]))
	for i := range maps {
		for hexbase, bits := range maps[i] {
			baseToBits[hexbase] |= bits
		}
	}
	sequences := make([]int64, 0, len(baseToBits)*30)
	for hexbase, bits := range baseToBits {
		base, err := strconv.ParseInt(hexbase, 16, 64)
		if err != nil {
			return nil, errors.Annotatef(err, "presence cannot parse alive key: %q", base)
		}
		base *= 63
		for i := int64(0); i < 63 && bits > 0; i++ {
			on := (bits&1 == 1)
			bits >>= 1
			if !on {
				continue
			}
			seq := base + i
			sequences = append(sequences, seq)
		}
	}
	return sequences, nil
}
816233
func Filter(ftype string) simplestreams.AppendMatchingFunc {
	return func(source simplestreams.DataSource, matchingImages []interface{},
		images map[string]interface{}, cons simplestreams.LookupConstraint) ([]interface{}, error) {

		imagesMap := make(map[imageKey]*Metadata, len(matchingImages))
		for _, val := range matchingImages {
			im := val.(*Metadata)
			imagesMap[imageKey{im.Arch, im.FType, im.Release, im.Version}] = im
		}
		for _, val := range images {
			im := val.(*Metadata)
			if ftype != "" {
				if im.FType != ftype {
					continue
				}
			}
			if _, ok := imagesMap[imageKey{im.Arch, im.FType, im.Release, im.Version}]; !ok {
				matchingImages = append(matchingImages, im)
			}
		}
		return matchingImages, nil
	}
}