Exemple #1
0
func createSketch(info *abstract.Info) (*SketchProxy, error) {
	var sketch abstract.Sketch
	var err error
	manager := storage.GetManager()
	err = manager.Create(info.ID)
	if err != nil {
		return nil, errors.New("Error creating new sketch")
	}

	switch info.Type {
	case abstract.HLLPP:
		sketch, err = hllpp.NewSketch(info)
	case abstract.TopK:
		sketch, err = topk.NewSketch(info)
	case abstract.CML:
		sketch, err = cml.NewSketch(info)
	default:
		return nil, errors.New("Invalid sketch type: " + info.Type)
	}
	if err != nil {
		return nil, errors.New("Error creating new sketch")
	}

	sp := SketchProxy{info, sketch, sync.RWMutex{}, 0, true}
	err = storage.GetManager().Create(info.ID)
	if err != nil {
		return nil, err
	}

	sp.save(true)
	go sp.autosave()
	return &sp, nil
}
Exemple #2
0
func createSketch(info *abstract.Info) (*SketchProxy, error) {
	var sketch abstract.Sketch
	var err error

	if err != nil {
		return nil, errors.New("Error creating new sketch")
	}

	switch info.Type {
	case abstract.HLLPP:
		sketch, err = hllpp.NewSketch(info)
	case abstract.TopK:
		sketch, err = topk.NewSketch(info)
	case abstract.CML:
		sketch, err = cml.NewSketch(info)
	case abstract.Dict:
		sketch, err = dict.NewSketch(info)
	case abstract.Bloom:
		sketch, err = bloom.NewSketch(info)
	default:
		return nil, errors.New("Invalid sketch type: " + info.Type)
	}
	if err != nil {
		return nil, errors.New("Error creating new sketch")
	}

	sp := SketchProxy{info, sketch, sync.RWMutex{}, 0, true}
	sp.save(true)
	go sp.autosave()
	return &sp, nil
}