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

Using string or map or JSON object as a value for a key. #31

Open
pawelurbanski opened this issue Jul 21, 2020 · 2 comments
Open

Using string or map or JSON object as a value for a key. #31

pawelurbanski opened this issue Jul 21, 2020 · 2 comments

Comments

@pawelurbanski
Copy link

Dear Team,
Is it possible to assign a string / map / JSON object to a key? The documentation and examples speak of uint64.
If not, is it possible to get an index to the key that uniquely points to the key as a kind of hash / pointer one could use as a key in a map to attach some more metadata to the key that just an integer value available by default?

Thanks for any hints...

@mschoch
Copy link
Contributor

mschoch commented Jul 21, 2020

Initially we planned to build this into the library, but it turns out all of our use cases so far have been satisfied with this simpler API.

  1. If you're going to persist the vellum to disk anyway, you can persist your other data structures first, and then when you build the vellum, the uint64 value you assign to the keys is simply the file offset of your other more complex data-structure. This is how bleve's file format zap does things. We first persist the roaring bitmap data-structures to disk (things we want to be the value we can lookup in vellum) Then when we insert into vellum, we associate the file offsets of those data-structures (uint64) with the keys. Then later when we use vellum for a lookup, we take the uint64, and use it to find the roaring bitmaps elsewhere in the file. This is very convenient if you plan to mmap the file anyway.

  2. If you're not persisting this to disk, and working with it purely in memory, then you could simply keep another map along side the vellum instance, and you can make the key to your map be the uint64 you associate with the vellum key. For example:

side := make(map[uint64]YourOwnStruct)

Then, you place your data into this side structure, and then insert the data into vellum, with the value being the key into your side structure. Later if you look up something in vellum, it returns to you the key in your side structure when you can find the rest of the data.

Hope this helps.

@pawelurbanski
Copy link
Author

pawelurbanski commented Jul 21, 2020 via email

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