Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to dumps/loads cuckoofilter from file? #23

Open
FelixSeptem opened this issue Jan 29, 2019 · 4 comments
Open

How to dumps/loads cuckoofilter from file? #23

FelixSeptem opened this issue Jan 29, 2019 · 4 comments

Comments

@FelixSeptem
Copy link

I have three question before import cuckoofilter into my project:

  1. how to dumps and loads cuckoofilter from file in order to failover?
  2. what's recommend ratio for data size/cuckoofilter size?
  3. how to resize cuckoofilter for scale purpose?
@0xleizhang
Copy link

@FelixSeptem maybe we can fork this repo. change all field to start with capital . serialize to json to dump. load json to filter .

@FelixSeptem
Copy link
Author

@FelixSeptem maybe we can fork this repo. change all field to start with capital . serialize to json to dump. load json to filter .

gob maybe a better choice in Golang to serialize and deserialize

@0xleizhang
Copy link

@FelixSeptem we don't need do it self .the api has Encode Decode method.

func (cf *Filter) Encode() []byte 

func Decode(bytes []byte) (*Filter, error)

@0xleizhang
Copy link

complete code

var (
	//todo autoresize
	filter = cuckoo.NewFilter(1000)
)

const (
	fileName = "cuckoo-filter.data"
)

func GetFilter() *cuckoo.Filter {

	bytes, err := ioutil.ReadFile(fileName)

	if err == nil {
		decodeFilter, decodeError := cuckoo.Decode(bytes)
		if decodeError == nil {
			filter = decodeFilter
		}
	}

	return filter
}

func DumpFilter() {

	bytes := filter.Encode()
	err := ioutil.WriteFile(fileName, bytes, 0755)
	if err != nil {
		log.Error(err.Error())
	}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants