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

Proposal: Make Red-Black tree in std.rb generic #2

Open
joachimschmidt557 opened this issue Aug 6, 2020 · 4 comments
Open

Proposal: Make Red-Black tree in std.rb generic #2

joachimschmidt557 opened this issue Aug 6, 2020 · 4 comments

Comments

@joachimschmidt557
Copy link
Member

At the moment, the implementation of red-black trees in the standard library are not generic and need to be embedded in other structs in order to work as intended.

https://github.com/ziglang/zig/blob/a2bb246db4c2bb88f402215d5db79a535dbff4b6/lib/std/rb.zig#L16-L27

This is in contrast to other data structures in the standard library such as the linked lists, which are generic:

https://github.com/ziglang/zig/blob/a2bb246db4c2bb88f402215d5db79a535dbff4b6/lib/std/linked_list.zig#L15

https://github.com/ziglang/zig/blob/a2bb246db4c2bb88f402215d5db79a535dbff4b6/lib/std/linked_list.zig#L164

https://github.com/ziglang/zig/blob/a2bb246db4c2bb88f402215d5db79a535dbff4b6/lib/std/atomic/queue.zig#L10

https://github.com/ziglang/zig/blob/a2bb246db4c2bb88f402215d5db79a535dbff4b6/lib/std/atomic/stack.zig#L8

Are there any downsides to making the RBTree Node and Tree data structures generic like the other pointer-oriented data structures?

@daurnimator
Copy link
Contributor

This is in contrast to other data structures in the standard library such as the linked lists, which are generic

I've seen it proposed that the genericity of the other data structures should be removed. ziglang/zig#5584 is the only related issue I can find right now though

@joachimschmidt557
Copy link
Member Author

joachimschmidt557 commented Aug 9, 2020

I see the point in having these pointer-oriented data structures be non-generic: If we have the item stored, we can immediately access the node "containing" the item.

I would advocate for a unified handling of generics in these pointer-oriented data structures then. Either we have all of them generic or all of them non-generic. It would help with removing confusion, I think.

@tadeokondrak
Copy link

std.rb is no longer in the standard library: ziglang/zig@6368519

@andrewrk andrewrk transferred this issue from ziglang/zig Sep 30, 2020
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

4 participants