Skip to content

Match std::collections API #11

@tapeinosyne

Description

@tapeinosyne

For collections, it is generally desirable to match the standard library API where feasible. By and large, qp_trie already offers the methods one would expect from a trie, but there remain a few edges where the interface could be smoothed out to better fit the expectations created by std.

The missing methods that can be immediately implemented with no internal changes are:

  • clear
  • is_empty
  • contains_key
  • Keys iterator
  • Values, ValuesMut iterators

Some that would require some work or discussion, but are clearly useful:

  • O(1) len,

    (As already noted in the source.) While not strictly expected of a trie, constant-time length would make it easier to make iterators exactly sized, with benefits to allocation and serialization.

  • drain

    In std, Drain iterators remove and yield a range of elements from a collection, without consuming the collection itself. (The specific behavior varies.) QP-tries could offer a draining prefix iterator, which would be roughly complementary to remove_prefix.

  • retain

    A convenience function to remove all elements that do not meet a given predicate.

At a glance, with the QP-tries being recursive, methods related to preallocation would require some significant restructuring to be effective, and the returns might be suspect:

  • reserve/ with_capacity

  • specialized append

(I jotted down a patch for the methods in the first section, and will follow up on the rest later on.)

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