// GetSketches return a list of sketch tuples [name, type] func (m *Manager) GetSketches() [][2]string { sketches := tupleResult{} for _, v := range m.infos.info { sketches = append(sketches, [2]string{v.GetName(), datamodel.GetTypeString(v.GetType())}) } sort.Sort(sketches) return sketches }
// Get ... func (d *Dict) Get(data interface{}) (interface{}, error) { typ := d.Info.Sketch.GetType() switch datamodel.GetTypeString(typ) { case datamodel.Bloom: return d.getMemb(data) case datamodel.CML: return d.getFreq(data) case datamodel.HLLPP: return d.getCard(data) } return nil, fmt.Errorf("Unknown error: %v", d.Info.GetType().String()) // FIXME: return some error }
// Get ... func (sp *SketchProxy) Get(data interface{}) (interface{}, error) { switch datamodel.GetTypeString(sp.GetType()) { case datamodel.HLLPP: return sp.sketch.Get(nil) case datamodel.CML: return sp.sketch.Get(data) case datamodel.TopK: return sp.sketch.Get(nil) case datamodel.Bloom: return sp.sketch.Get(data) default: return nil, fmt.Errorf("Invalid sketch type: %s", sp.GetType()) } }
// CreateSketch ... func CreateSketch(info *datamodel.Info) (*SketchProxy, error) { var err error var sketch datamodel.Sketcher sp := &SketchProxy{info, sketch, sync.RWMutex{}} switch datamodel.GetTypeString(info.GetType()) { case datamodel.HLLPP: sp.sketch, err = NewHLLPPSketch(info) case datamodel.CML: sp.sketch, err = NewCMLSketch(info) case datamodel.TopK: sp.sketch, err = NewTopKSketch(info) case datamodel.Bloom: sp.sketch, err = NewBloomSketch(info) default: return nil, fmt.Errorf("Invalid sketch type: %s", sp.GetType()) } if err != nil { return nil, err } return sp, nil }
// LoadSketch ... func LoadSketch(info *datamodel.Info, file *os.File) (*SketchProxy, error) { var sketch datamodel.Sketcher sp := &SketchProxy{info, sketch, sync.RWMutex{}} size, err := utils.GetFileSize(file) if err != nil { return nil, err } data := make([]byte, size, size) _, err = file.Read(data) if err != nil { return nil, fmt.Errorf("Error loading data for sketch: %s", info.ID()) } switch datamodel.GetTypeString(info.GetType()) { case datamodel.HLLPP: sp.sketch = &HLLPPSketch{} err = sp.sketch.Unmarshal(info, data) case datamodel.CML: sp.sketch = &CMLSketch{} err = sp.sketch.Unmarshal(info, data) case datamodel.TopK: sp.sketch = &TopKSketch{} err = sp.sketch.Unmarshal(info, data) case datamodel.Bloom: sp.sketch = &BloomSketch{} err = sp.sketch.Unmarshal(info, data) default: return nil, fmt.Errorf("Invalid sketch type: %s", sp.GetType()) } if err != nil { return nil, err } return sp, nil }
func isValidType(info *datamodel.Info) bool { if info.Type == nil { return false } return len(datamodel.GetTypeString(info.GetType())) != 0 }