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

Entry for abhinav-upadhyay #696

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Copy link
Owner

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.

if (row == null) {
Expand All @@ -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) {
Copy link
Owner

Choose a reason for hiding this comment

The 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;
}

Expand Down Expand Up @@ -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) {
Expand Down
Loading