func NewLongsSketchFromString()

in frequencies/longs_sketch.go [180:255]


func NewLongsSketchFromString(str string) (*LongsSketch, error) {
	if len(str) < 1 {
		return nil, errors.New("string is empty")
	}
	// Remove trailing comma if present
	// as this will cause a problem with the split
	if str[len(str)-1] == ',' {
		str = str[:len(str)-1]
	}
	tokens := strings.Split(str, ",")
	if len(tokens) < (strPreambleTokens + 2) {
		return nil, fmt.Errorf("string not long enough: %d", len(tokens))
	}
	serVe, err := strconv.ParseInt(tokens[0], 10, 32)
	if err != nil {
		return nil, err
	}
	famID, err := strconv.ParseInt(tokens[1], 10, 32)
	if err != nil {
		return nil, err
	}
	lgMax, err := strconv.ParseInt(tokens[2], 10, 32)
	if err != nil {
		return nil, err
	}
	flags, err := strconv.ParseInt(tokens[3], 10, 32)
	if err != nil {
		return nil, err
	}
	streamWt, err := strconv.ParseInt(tokens[4], 10, 64)
	if err != nil {
		return nil, err
	}
	offset, err := strconv.ParseInt(tokens[5], 10, 64)
	if err != nil {
		return nil, err
	}
	//should always get at least the next 2 from the map
	numActive, err := strconv.ParseInt(tokens[6], 10, 32)
	if err != nil {
		return nil, err
	}
	lgCurOrigin, err := strconv.ParseUint(tokens[7], 10, 32)
	if err != nil {
		return nil, err
	}
	lgCur := bits.TrailingZeros64(lgCurOrigin)

	//checks
	if serVe != _SER_VER {
		return nil, fmt.Errorf("possible Corruption: Bad SerVer: %d", serVe)
	}
	if famID != int64(internal.FamilyEnum.Frequency.Id) {
		return nil, fmt.Errorf("possible Corruption: Bad Family: %d", famID)
	}
	empty := flags > 0
	if !empty && (numActive == 0) {
		return nil, fmt.Errorf("Possible Corruption: !Empty && NumActive=0;  strLen: %d", numActive)
	}
	numTokens := int64(len(tokens))
	if (2 * numActive) != (numTokens - strPreambleTokens - 2) {
		return nil, fmt.Errorf("possible Corruption: Incorrect # of tokens: %d, numActive: %d", numTokens, numActive)
	}
	//    if ((2 * numActive) != (numTokens - STR_PREAMBLE_TOKENS - 2)) {
	sk, err := NewLongsSketch(int(lgMax), int(lgCur))
	if err != nil {
		return nil, err
	}
	sk.streamWeight = streamWt
	sk.offset = offset
	sk.hashMap, err = deserializeFromStringArray(tokens)
	if err != nil {
		return nil, err
	}
	return sk, nil
}