Skip to content

Support rank and select operations? #3

Description

@vaibhavsagar

It would be wonderful to use these bitvectors as rank/select dictionaries.

Activity

  1. recursion-ninja commented on Feb 12, 2019

    @recursion-ninja
    Owner

    This should be doable based on my reading of this description of the operations.

    I'll explore whether an auxiliary data structure will need to be added to the BitVector type and then maintained after each mutable operation, or if the auxiliary structure can be created as needed when rank or select are called on the BitVector.

    I won't have a lot of free time to implement this for a while. If you're interested in implementing a pull request, it would be welcomed.

  2. vaibhavsagar commented on Feb 12, 2019

    @vaibhavsagar
    Author

    I think the current state of the art is http://www.cs.cmu.edu/~./dongz/papers/poppy.pdf. There's an implementation of this at https://github.com/Gabriel439/Haskell-Succinct-Vector-Library.

  3. recursion-ninja commented on Jul 18, 2019

    @recursion-ninja
    Owner

    I apologize for the delay @vaibhavsagar , I've had other priorities the last few months. I have implemented the rank & select functions on the rank-select branch. Please take a look at the new functionality.

    The functions currently have the following type signatures:

    rank :: BitVector -> Word -> Word
    select :: BitVector -> Word -> Maybe Word
    

    Both employ "broadword programming" for their implementation and do not allocate any additional memory structures within the BitVector data type. The advantage of this technique is that there is no additional memory overhead for users that do not require the BitVector to be a succinct data structure. The downside is that rank and select are not as efficient as possible (O(1) time). It's important for me and our use-case at AMNH that the BitVector type not allocate any more memory than required for our functionality.

    I did consider the following functions instead:

    succinctDictionary :: BitVector -> SuccinctDictionary
    rank :: Maybe SuccinctDictionary -> BitVector -> Word -> Word
    select :: Maybe SuccinctDictionary -> BitVector -> Word -> Maybe Word
    

    With this interface, a Nothing :: Maybe SuccinctDictionary value indicates to use the "broadword programming" technique for efficiency reason. A Just v :: Maybe SuccinctDictionary value indicates using the pre-computed SuccinctDictionary for the BitVector because either the BitVector is so long it requires the dictionary for efficiency, or enough rank/select operations will be performed on this BitVector that pre-computing the dictionary is worth the time and space investment.

    There are advantages of this "interface." Notably, it allows for the creation of a SuccinctDictionary for users who require the BitVector type to be a succinct data structure in an "opt-in" manner. Additionally, this "interface" would allow for the implementation of rank & select that are truly O(1). The downside is that the SuccinctDictionary for a given BitVector will have to be manually tracked by the user. A second "downside" is that the algorithms described for constructing the succinct dictionaries are quite finicky, so it would require more time to implement than what I have done currently with the "broadword programming" technique. Finally literature has references that for small succinct data structures, "broadword programming" tends to outperform the use of succinct dictionaries until the size of the BitVector scales very large.

    I'm open to merging and uploading what I have now to hackage. However, if you're interested in creating a pull request for an implementation along the lines of the second interface I just described, I'm open to the contribution.

    Let me know what you think about the current implementation and the possible pull request.

  4. vaibhavsagar commented on Jul 18, 2019

    @vaibhavsagar
    Author

    This looks great, thank you for implementing it! I'm not sure I'll have time to contribute a pull request using succinct dictionaries anytime soon, unfortunately 😦.

  5. recursion-ninja commented on Jul 18, 2019

    @recursion-ninja
    Owner

    I'm not sure I'll have time to contribute a pull request using succinct dictionaries anytime soon, unfortunately frowning.

    @vaibhavsagar you and me both!

    I'll merge this branch into master, tag a new release, and upload to hackage tomorrow.

  6. recursion-ninja commented on Jul 22, 2019

    @recursion-ninja
    Owner

    New release is up. See 34ef18b for the 1.1.0 tag.

  7. vaibhavsagar commented on Jul 22, 2019

    @vaibhavsagar
    Author

    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions