Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Use hash set instead of array list for performance#7

Merged
TheDGOfficial merged 3 commits intomainfrom
performance/use-hashset
Feb 17, 2021
Merged

Use hash set instead of array list for performance#7
TheDGOfficial merged 3 commits intomainfrom
performance/use-hashset

Conversation

@TheDGOfficial
Copy link
Copy Markdown
Member

Changes made in this Pull Request

Changed duplicate entry tracker to use HashSet instead of ArrayList for performance.

Reason of the above changes are

We only use the contains and add methods, we are not adding duplicate entries, and we use String, each String should have unique hash code. So, we can use HashSet instead.

Other information about this Pull Request

By using HashSet instead of ArrayList, we can gain a performance improvement.

ArrayList#contains compute time is O(n), where as HashSet's one is O(1). So, the more entries on the ArrayList, the more time it will take for the contains method.

We only use the contains and add methods, and do not add duplicate entries,
and we use String, each String should have unique hash code.

So, by using HashSet instead of ArrayList, we can gain a performance improvement
somewhere between %5 to %10.
@TheDGOfficial TheDGOfficial added the enhancement New feature or request label Feb 17, 2021
@TheDGOfficial TheDGOfficial added this to the v1.0 milestone Feb 17, 2021
@TheDGOfficial TheDGOfficial self-assigned this Feb 17, 2021
@TheDGOfficial TheDGOfficial enabled auto-merge (squash) February 17, 2021 16:32
@TheDGOfficial TheDGOfficial merged commit f67c53d into main Feb 17, 2021
@TheDGOfficial TheDGOfficial deleted the performance/use-hashset branch February 17, 2021 16:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant