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

Not generating unique keys for the nodes #29

Closed
busslina opened this issue Oct 17, 2023 · 4 comments
Closed

Not generating unique keys for the nodes #29

busslina opened this issue Oct 17, 2023 · 4 comments

Comments

@busslina
Copy link

busslina commented Oct 17, 2023

I got this error (

if (children.containsKey(node.key)) throw DuplicateKeyException(node.key);
) when I have a Node with a lot of children.

In my case it happens (sometimes) when I open this tree location (/bin/), where there are a lot of children.

I bypass this error by providing a String key to every node.

I suggest that maybe you can provide an int instead of String (2^64 unique keys is enough).

Also I tried to use int keys like this: '$keyIndex++', but I got same error: (0 key is yet used, 1 key is yet used, ...).

@jawwad-hassan89
Copy link
Contributor

jawwad-hassan89 commented Nov 4, 2023

Do you get the DuplicateKeyException with the default keys or with the custom keys?
Using an int key would not work, as the keys are used to compute the path, so any Key, will need to have a toString() override.
If its an issue with the default implementation, then rather then using the UniqueKey, I can update it to use a UUID instead.

You can test your code by using one the of UUID, let me if it resolves the issue for you.

@jawwad-hassan89
Copy link
Contributor

I looked into this issue, and apparently, if the child count is more than 10,000, then the duplicate keys started to appear at a rate of 0.3-0.4%. I have replaced the UniqueKey with Uuid for generating the keys, and now the issue has been resolved.
There are no duplicate keys even at 100,000 children.

https://github.com/jawwad-hassan89/animated_tree_view/blob/d71497b6e6107a2ab356d54d38d3f24a3b4c6f0a/test/node/node_test.dart#L50

@busslina
Copy link
Author

busslina commented Nov 5, 2023

Yeah, it was happening when opening large directories multiple times. The best solution would be with no limit. Why you don't give a try to GlobalKey?

I read somewhere that is not real guaranty of uniqueness with uuid

@jawwad-hassan89
Copy link
Contributor

Uuids are guaranteed to be unique within a system. As we are only concerned with uniqueness within the local system that is generating the Uuids, so they will be unique. Theoretically, there is no limit to how many Uuids can be generated, however I have only tested upto 100,000 entries.

Relevant ancillary documentation:
[1][2]
Identifier uniqueness considerations:
This document specifies three algorithms to generate UUIDs: the
first leverages the unique values of 802 MAC addresses to
guarantee uniqueness, the second uses pseudo-random number
generators, and the third uses cryptographic hashing and
application-provided text strings. As a result, the UUIDs
generated according to the mechanisms here will be unique from all
other UUIDs that have been or will be assigned.

A Universally Unique IDentifier (UUID) URN Namespace

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