Skip to content

Add Open Addressing Hash Map#12

Closed
hungcq wants to merge 5 commits intomindxhub:masterfrom
hungcq:master
Closed

Add Open Addressing Hash Map#12
hungcq wants to merge 5 commits intomindxhub:masterfrom
hungcq:master

Conversation

@hungcq
Copy link
Copy Markdown

@hungcq hungcq commented Jun 1, 2020

No description provided.

@hungcq hungcq requested a review from cuonghq104 June 1, 2020 13:16
@hungcq hungcq linked an issue Jun 1, 2020 that may be closed by this pull request
Copy link
Copy Markdown

@cuonghq104 cuonghq104 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!!

@trungducc trungducc requested a review from hellovietduc June 4, 2020 08:21
@trungducc
Copy link
Copy Markdown
Contributor

@vietduc01100001 Please help to take a look

Copy link
Copy Markdown

@hellovietduc hellovietduc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create separate PRs for each issue. Don't mix Array or Linked List in Hash Map PR.

Plus, please add test cases and if possible set up GitHub Actions to run it automatically, and everyone can see the result as well.

src/Array.java Outdated
Comment on lines +25 to +26
public int itemAt(int index) {
if (index > size - 1) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we pass -1, -2 or -3000 to this function? Would it throw an error? Or should we handle it nicely?

Comment on lines +38 to +39
public boolean insert(int item, int index) {
if (index == size) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, you should validate the index parameter.

src/Array.java Outdated
Comment on lines +56 to +59
if (arr.length == 0) {
arr = new int[1];
return;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You won't need to handle this edge case if you choose a good default capacity.

src/Array.java Outdated
return;
}
if (size > arr.length) {
int[] newArr = new int[arr.length * 2];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid hard-coding the grow factor 2 into the function.

src/Array.java Outdated
Comment on lines +77 to +78
public int removeAt(int index) {
if (index >= size - 1) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate the index parameter when it's a negative integer.

src/Array.java Outdated
Comment on lines +92 to +93
if (size <= arr.length / 4) {
int[] newArr = new int[arr.length / 2];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, avoid hard-coding "magic numbers".

@hungcq hungcq closed this Nov 18, 2024
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.

Implement HashTable with Open Addressing

4 participants