-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Entry for abhinav-upadhyay #696
Closed
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a110004
Add entry for GH user abhinav-upadhyay.
abhinav-upadhyay 3a1d351
Fix output
abhinav-upadhyay baca219
Remove extra calls to min and max
abhinav-upadhyay 10c68a1
Rename the script
abhinav-upadhyay 833ff01
Hanle hash collisions
abhinav-upadhyay 3429050
Fix the handling of hash collisions
abhinav-upadhyay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,6 @@ private static class Table { | |
|
||
public void put(long cityStartOffset, long cityLength, long nameHash, int temperature) { | ||
final long uhash = nameHash ^ (nameHash >> 29); | ||
// final long uhash = nameHash; | ||
int index = (int) uhash & TABLE_MASK; | ||
Row row = table[index]; | ||
if (row == null) { | ||
|
@@ -72,7 +71,21 @@ public void put(long cityStartOffset, long cityLength, long nameHash, int temper | |
for (; i < cityLength; i++) { | ||
array[i] = UNSAFE.getByte(cityStartOffset++); | ||
} | ||
table[index] = new Row(new String(array, 0, i), temperature, temperature, 1, temperature, (int) uhash); | ||
table[index] = new Row(new String(array, 0, i), temperature, temperature, 1, temperature, uhash); | ||
return; | ||
} | ||
|
||
while (row.hash != uhash) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checking the hash isn't enough, you'll need to compare the actual name to differentiate between multiple stations with the same hash. |
||
index = (int) ((index + (uhash)) & TABLE_MASK); | ||
int i = 0; | ||
for (; i < cityLength - 1;) { | ||
array[i++] = UNSAFE.getByte(cityStartOffset++); | ||
array[i++] = UNSAFE.getByte(cityStartOffset++); | ||
} | ||
for (; i < cityLength; i++) { | ||
array[i] = UNSAFE.getByte(cityStartOffset++); | ||
} | ||
table[index] = new Row(new String(array, 0, i), temperature, temperature, 1, temperature, uhash); | ||
return; | ||
} | ||
|
||
|
@@ -214,7 +227,7 @@ public static void main(String[] args) throws IOException { | |
final long fileSize = fc.size(); | ||
final long startAddress = fc.map(FileChannel.MapMode.READ_ONLY, 0, fileSize, Arena.global()).address(); | ||
final long endAddress = startAddress + fileSize; | ||
final long[][] segments = findSegments(startAddress, endAddress, fileSize, fileSize > 1024 * 1024 * 1024 ? 8 : 1); | ||
final long[][] segments = findSegments(startAddress, endAddress, fileSize, fileSize > 1024 * 1024 * 1024 ? 12 : 1); | ||
final List<Table> collect = Arrays.stream(segments).parallel().map(s -> readFile(s[0], s[1])).toList(); | ||
Map<String, Row> finalMap = new TreeMap<>(); | ||
for (final Table t : collect) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to handle collisions, otherwise you'd aggregate the values from several stations with the same hash.