// Compact serializes the JWS into its "compact" form per
// https://tools.ietf.org/html/rfc7515#section-7.1
509508
func (j *jws) Compact(key interface{}) ([]byte, error) {
	if len(j.sb) < 1 {
		return nil, ErrNotEnoughMethods
	}

	if err := j.sign(key); err != nil {
		return nil, err
	}

	sig, err := j.sb[0].Signature.Base64()
	if err != nil {
		return nil, err
	}
	return format(
		j.sb[0].Protected,
		j.plcache,
		sig,
	), nil
}
897346
func (ss *FileSubStore) shouldCompact() bool {
	// Gobal switch
	if !ss.opts.CompactEnabled {
		return false
	}
	// Check that if minimum file size is set, the client file
	// is at least at the minimum.
	if ss.opts.CompactMinFileSize > 0 && ss.fileSize < ss.opts.CompactMinFileSize {
		return false
	}
	// Check fragmentation
	frag := 0
	if ss.numRecs == 0 {
		frag = 100
	} else {
		frag = ss.delRecs * 100 / ss.numRecs
	}
	if frag < ss.opts.CompactFragmentation {
		return false
	}
	// Check that we don't compact too often
	if time.Since(ss.compactTS) < ss.compactItvl {
		return false
	}
	return true
}
778593
func (db *DB) EnableCompactions() {
	db.autoCompactMtx.Lock()
	defer db.autoCompactMtx.Unlock()

	db.autoCompact = true
	level.Info(db.logger).Log("msg", "compactions enabled")
}
871382
func (j *jws) Serialize(key interface{}) ([]byte, error) {
	if j.isJWT {
		return j.Compact(key)
	}
	return nil, ErrIsNotJWT
}
1048099
func compactPoints(points []point) []point {
	compactedPoints := make([]point, 0)

	for _, sourcePoint := range points {
		keepPoint := true

		for _, compactPoint := range compactedPoints {
			if !tagSetsMatch(sourcePoint.Tags, compactPoint.Tags) {
				continue
			}

			keepPoint = false
			for key, val := range sourcePoint.Fields {
				compactPoint.Fields[key] = val
			}
		}

		if keepPoint {
			compactedPoints = append(compactedPoints, sourcePoint)
		}
	}

	return compactedPoints
}
399635
func (h *BytesRefHash) Sort(comp func(a, b []byte) bool) []int {
	compact := h.compact()
	s := newBytesRefIntroSorter(h, compact, comp)
	s.Sort(0, h.count)
	// TODO remove this
	// for i, _ := range compact {
	// 	if compact[i+1] == -1 {
	// 		break
	// 	}
	// 	assert(!s.Less(i+1, i))
	// 	if ok := !s.Less(i+1, i); !ok {
	// 		fmt.Println("DEBUG1", compact)
	// 		assert(ok)
	// 	}
	// }
	return compact
}
1235586
func (db *Database) Compact(start []byte, limit []byte) error {
	return errors.New("unsupported operation")
}
948877
func (ic *IncrementalCompact) Load(ctx context.Context, sess rets.Requester, url string) error {
	// extract an id'd subesection of metadata
	get := func(id, mtype string) (*rets.CompactMetadata, error) {
		if id == "" {
			id = "0"
		}
		params := rets.MetadataParams{
			Format: "COMPACT",
			MType:  mtype,
			ID:     id,
		}
		req := rets.MetadataRequest{
			URL:            url,
			MetadataParams: params,
		}
		reader, er := rets.MetadataStream(rets.MetadataResponse(ctx, sess, req))
		if er != nil {
			return nil, er
		}
		return rets.ParseMetadataCompactResult(reader)
	}
	msys, err := get("", metadata.MISystem.Name)
	if err != nil {
		return err
	}
	ic.Response = msys.Response
	ic.MSystem = msys.MSystem
	ic.Elements = map[string][]rets.CompactData{}
	// fmt.Printf("compact system: %v\n", compact)
	cds, err := ic.extractChildren(get, []string{}, metadata.MISystem)
	if err != nil {
		return err
	}
	for _, cd := range cds {
		// extract children from this element and put in the system elem
		ic.Elements[cd.Element] = append(ic.Elements[cd.Element], cd)
	}
	return nil
}
540619
func (f *IndexFile) Compacting() bool {
	f.mu.RLock()
	v := f.compacting
	f.mu.RUnlock()
	return v
}
1076737
func (e *Engine) compactFull(grp CompactionGroup, wg *sync.WaitGroup) bool {
	s := e.fullCompactionStrategy(grp, false)
	if s == nil {
		return false
	}

	// Try the lo priority limiter, otherwise steal a little from the high priority if we can.
	if e.compactionLimiter.TryTake() {
		e.compactionTracker.IncFullActive()
		wg.Add(1)
		go func() {
			defer wg.Done()
			defer e.compactionTracker.DecFullActive()
			defer e.compactionLimiter.Release()
			s.Apply()
			// Release the files in the compaction plan
			e.CompactionPlan.Release([]CompactionGroup{s.group})
		}()
		return true
	}
	return false
}
1084887
func (c Context) addCompact(z *Big, X0 uint64, Xsign form, Y uint64, Ysign form, shift uint64) form {
	// Test whether X0 * 10^shift fits inside a uint64. If not, fall back to
	// big.Ints.
	X, ok := arith.MulPow10(X0, shift)
	if !ok {
		X0 := z.unscaled.SetUint64(X0)
		X := arith.MulBigPow10(X0, X0, shift)
		// Because hi was promoted to a big.Int, it by definition is larger than
		// lo.
		//
		// Therefore, the resulting signbit is the same as hi's signbit.
		//
		// Furthermore, we do not need to check if the result of the operation
		// is zero.
		if Xsign == Ysign {
			z.precision = arith.BigLength(arith.Add(&z.unscaled, X, Y))
			z.compact = cst.Inflated
		} else {
			arith.Sub(&z.unscaled, X, Y)
			z.norm()
		}
		return Xsign
	}

	// If the signs are the same, then X + Y = ℤ≠0.
	if Ysign == Xsign {
		if sum, c := arith.Add64(X, Y); c == 0 {
			z.compact = sum
			if sum == cst.Inflated {
				z.unscaled.SetUint64(cst.Inflated)
			}
			z.precision = arith.Length(z.compact)
		} else {
			arith.Set(&z.unscaled, c, sum)
			z.precision = 20
			z.compact = cst.Inflated
		}
		return Xsign
	}

	sign := Xsign
	// X + (-Y) == X - Y == -(Y - X)
	// (-X) + Y == Y - X == -(X - Y)
	diff, b := arith.Sub64(X, Y)
	if b != 0 {
		sign ^= signbit
		diff = Y - X
	}

	if diff != 0 {
		z.compact = diff
		z.precision = arith.Length(z.compact)
		return sign
	}

	// On a zero result:
	//
	//    Otherwise, the sign of a zero result is 0 unless either both operands
	//    were negative or the signs of the operands were different and the
	//    rounding is round-floor.
	//
	// - http://speleotrove.com/decimal/daops.html#refaddsub
	if c.RoundingMode == ToNegativeInf {
		sign = Xsign ^ Ysign // either 0 or 1
	}
	sign |= Xsign & Ysign

	z.compact = 0
	z.precision = 1
	return sign
}
863553
func compactCCC() {
	m := make(map[uint8]uint8)
	for i := range chars {
		c := &chars[i]
		m[c.ccc] = 0
	}
	cccs := []int{}
	for v, _ := range m {
		cccs = append(cccs, int(v))
	}
	sort.Ints(cccs)
	for i, c := range cccs {
		cccMap[uint8(i)] = uint8(c)
		m[uint8(c)] = uint8(i)
	}
	for i := range chars {
		c := &chars[i]
		c.origCCC = c.ccc
		c.ccc = m[c.ccc]
	}
	if len(m) >= 1<<6 {
		log.Fatalf("too many difference CCC values: %d >= 64", len(m))
	}
}
1255038
func CompactUnmarshal(bz []byte) (*CompactBitArray, error) {
	if len(bz) < 2 {
		return nil, errors.New("compact bit array: invalid compact unmarshal size")
	} else if bytes.Equal(bz, []byte("null")) {
		return NewCompactBitArray(0), nil
	}
	size, n := binary.Uvarint(bz)
	bz = bz[n:]
	if len(bz) != int(size+7)/8 {
		return nil, errors.New("compact bit array: invalid compact unmarshal size")
	}

	bA := &CompactBitArray{byte(int(size % 8)), bz}
	return bA, nil
}
37828
func (prof *Profiler) Serialize(inf *structs.DevInfo) []byte {
	// ensure the Builder is in a usable state.
	prof.Builder.Reset()
	devs := make([]fb.UOffsetT, len(inf.Device))
	names := make([]fb.UOffsetT, len(inf.Device))
	for i := 0; i < len(inf.Device); i++ {
		names[i] = prof.Builder.CreateString(inf.Device[i].Name)
	}
	for i := 0; i < len(inf.Device); i++ {
		flat.DeviceStart(prof.Builder)
		flat.DeviceAddName(prof.Builder, names[i])
		flat.DeviceAddRBytes(prof.Builder, inf.Device[i].RBytes)
		flat.DeviceAddRPackets(prof.Builder, inf.Device[i].RPackets)
		flat.DeviceAddRErrs(prof.Builder, inf.Device[i].RErrs)
		flat.DeviceAddRDrop(prof.Builder, inf.Device[i].RDrop)
		flat.DeviceAddRFIFO(prof.Builder, inf.Device[i].RFIFO)
		flat.DeviceAddRFrame(prof.Builder, inf.Device[i].RFrame)
		flat.DeviceAddRCompressed(prof.Builder, inf.Device[i].RCompressed)
		flat.DeviceAddRMulticast(prof.Builder, inf.Device[i].RMulticast)
		flat.DeviceAddTBytes(prof.Builder, inf.Device[i].TBytes)
		flat.DeviceAddTPackets(prof.Builder, inf.Device[i].TPackets)
		flat.DeviceAddTErrs(prof.Builder, inf.Device[i].TErrs)
		flat.DeviceAddTDrop(prof.Builder, inf.Device[i].TDrop)
		flat.DeviceAddTFIFO(prof.Builder, inf.Device[i].TFIFO)
		flat.DeviceAddTColls(prof.Builder, inf.Device[i].TColls)
		flat.DeviceAddTCarrier(prof.Builder, inf.Device[i].TCarrier)
		flat.DeviceAddTCompressed(prof.Builder, inf.Device[i].TCompressed)
		devs[i] = flat.DeviceEnd(prof.Builder)
	}
	flat.DevInfoStartDeviceVector(prof.Builder, len(devs))
	for i := len(inf.Device) - 1; i >= 0; i-- {
		prof.Builder.PrependUOffsetT(devs[i])
	}
	devsV := prof.Builder.EndVector(len(devs))
	flat.DevInfoStart(prof.Builder)
	flat.DevInfoAddTimestamp(prof.Builder, inf.Timestamp)
	flat.DevInfoAddDevice(prof.Builder, devsV)
	prof.Builder.Finish(flat.DevInfoEnd(prof.Builder))
	p := prof.Builder.Bytes[prof.Builder.Head():]
	// copy them (otherwise gets lost in reset)
	tmp := make([]byte, len(p))
	copy(tmp, p)
	return tmp
}
242278
func Compact(value interface{}) interface{} {
	arr := redirectValue(reflect.ValueOf(value))

	if arr.Kind() != reflect.Slice && arr.Kind() != reflect.Array {
		panic("First parameter must be array or slice")
	}

	sliceElemType := sliceElem(arr.Type())
	resultSliceType := reflect.SliceOf(sliceElemType)
	result := reflect.MakeSlice(resultSliceType, 0, 0)

	for i := 0; i < arr.Len(); i++ {
		elemVal := arr.Index(i)

		if elemVal.Kind() == reflect.Interface {
			elemVal = elemVal.Elem()
		}

		redirectedElemVal := redirectValue(elemVal)

		switch redirectedElemVal.Kind() {
		case reflect.Invalid:
			continue
		case reflect.Func:
			if redirectedElemVal.IsNil() {
				continue
			}
		case reflect.Map, reflect.Slice, reflect.Chan:
			if redirectedElemVal.Len() == 0 {
				continue
			}
		default:
			defaultValue := reflect.Zero(redirectedElemVal.Type()).Interface()
			if redirectedElemVal.Interface() == defaultValue {
				continue
			}
		}

		result = reflect.Append(result, elemVal)
	}

	return result.Interface()
}
1297099
func (p *Partition) Compact() {
	p.mu.Lock()
	defer p.mu.Unlock()
	p.compact()
}
1372725
func (db *DB) CompactRangeCF(cf *ColumnFamilyHandle, r Range) {
	cStart := byteToChar(r.Start)
	cLimit := byteToChar(r.Limit)
	C.rocksdb_compact_range_cf(db.c, cf.c, cStart, C.size_t(len(r.Start)), cLimit, C.size_t(len(r.Limit)))
}