Skip to content

Tresize&find by val#20

Open
FatAndreasbot wants to merge 4 commits into
kingledion:mainfrom
FatAndreasbot:Tresize&FindByVal
Open

Tresize&find by val#20
FatAndreasbot wants to merge 4 commits into
kingledion:mainfrom
FatAndreasbot:Tresize&FindByVal

Conversation

@FatAndreasbot
Copy link
Copy Markdown

Added some wanted by me functionality

@kingledion
Copy link
Copy Markdown
Owner

Depending on your use case, if you really want to search by value, you have two options for a well implemented function.

  1. You can hash the value T that you want to store and then use that hash as the primary key. Then, use the existing Find function to return your desired Node(s)
  2. If you still need a distinct primary key, you can implement an optional second index on values. This would work like the above, it would store a map of the hashed values of T to pointers to the desired Node.

The first would be best implemented as a wrapper around this code, the second would be an addition to this.

Both of these solutions will be much faster O(1), at the cost of some additional memory allocation.

@FatAndreasbot
Copy link
Copy Markdown
Author

The issue with a hash index is that we can store identical data in the same tree. That's why I created two methods for the Tree structure. "FindByValue", which returns the first found, and a false "ok" value, if the node data is not unique. And "FindMultipleByValue", which will return a list of all nodes with the searched data/value.

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

Successfully merging this pull request may close these issues.

2 participants