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

Пелогейко Макар, ИТМО DWS, Stage 4 #145

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ebc1daf
[stage 1]
makar-pelogeiko Feb 20, 2024
1e51786
[stage 1]
makar-pelogeiko Feb 20, 2024
633a3d5
[stage 1]
makar-pelogeiko Feb 20, 2024
a8a5adf
[stage 1]
makar-pelogeiko Feb 20, 2024
1c60773
[stage 1]
makar-pelogeiko Feb 20, 2024
0bb809d
Merge branch 'main' into stage2
makar-pelogeiko Feb 28, 2024
1d491b1
stage 2 working draft implementation
makar-pelogeiko Feb 28, 2024
414f4c6
stage 2
makar-pelogeiko Feb 28, 2024
a54c8ac
Merge branch 'main' into stage2
incubos Mar 3, 2024
5b4a9f0
[stage 2]
makar-pelogeiko Mar 5, 2024
239544d
[stage 2]
makar-pelogeiko Mar 5, 2024
11a66cd
[stage2]
makar-pelogeiko Mar 6, 2024
0e4124c
[stage2]
makar-pelogeiko Mar 6, 2024
2350d3c
[stage2]
makar-pelogeiko Mar 6, 2024
8d01c4f
[stage2]
makar-pelogeiko Mar 6, 2024
0080206
Merge branch 'main' into stage3
makar-pelogeiko Mar 9, 2024
69be50b
[stage3]
makar-pelogeiko Mar 9, 2024
7f0b339
[stage3]
makar-pelogeiko Mar 9, 2024
598b24c
[stage3]
makar-pelogeiko Mar 9, 2024
42c1d3c
[stage3]
makar-pelogeiko Mar 16, 2024
862c83f
[stage3]
makar-pelogeiko Mar 20, 2024
6041a53
Merge branch 'main' into stage3
makar-pelogeiko Mar 20, 2024
df812f1
[stage 3]
makar-pelogeiko Mar 20, 2024
1858904
[stage3]
makar-pelogeiko Mar 20, 2024
a1751fe
[stage3]
makar-pelogeiko Mar 20, 2024
4103d86
Merge branch 'main' into stage4
makar-pelogeiko Mar 27, 2024
73828de
[stage4]
makar-pelogeiko Mar 28, 2024
fcfaa4d
[stage4]
makar-pelogeiko Mar 28, 2024
3f77bdb
[stage4]
makar-pelogeiko Mar 28, 2024
308cfc5
[stage4]
makar-pelogeiko Mar 28, 2024
1156ecc
[stage4]
makar-pelogeiko Mar 28, 2024
ad5690b
[convertor feature]
makar-pelogeiko Apr 3, 2024
ce2aac7
[report]
makar-pelogeiko Apr 3, 2024
5890455
[report it self + code style]
makar-pelogeiko Apr 3, 2024
86394a0
Merge branch 'main' into stage4
makar-pelogeiko May 25, 2024
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
63 changes: 63 additions & 0 deletions src/main/java/ru/vk/itmo/test/pelogeikomakar/Convertor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ru.vk.itmo.test.pelogeikomakar;

import ru.vk.itmo.dao.BaseEntry;
import ru.vk.itmo.dao.Entry;

import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.nio.charset.StandardCharsets;

public final class Convertor {

private Convertor() {
throw new UnsupportedOperationException("cannot be instantiated");
}

public static byte[] addLongToArray(long l, byte[] given) {
int gLength = 0;
if (given != null) {
gLength = given.length;
}
byte[] result = new byte[Long.BYTES + gLength];
for (int i = 0; i < Long.BYTES; ++i) {
result[i] = (byte)(l & 0xFF);
l >>= Byte.SIZE;
}

if (given != null) {
System.arraycopy(given, 0, result, 8, given.length);
} else {
result[Long.BYTES - 1] = (byte)(result[Long.BYTES - 1] | 0x80);
}

return result;
}

public static long getTimeStamp(MemorySegment segment) {
long time = segment.get(ValueLayout.JAVA_LONG_UNALIGNED, 0);

if (((time >> (Byte.SIZE * 7)) & 0x80) != 0) {
time &= ~(1L << 63);
}
return time;
}

public static boolean isValNull(MemorySegment segment) {
long time = segment.get(ValueLayout.JAVA_LONG_UNALIGNED, 0);
return ((time >> (Byte.SIZE * 7)) & 0x80) != 0;
}

public static MemorySegment stringToMemorySegment(String str) {
return MemorySegment.ofArray(str.getBytes(StandardCharsets.UTF_8));
}

public static Entry<MemorySegment> requestToEntry(String key, byte[] value, long timeStamp) {
byte[] storedValue = addLongToArray(timeStamp, value);
return new BaseEntry<>(stringToMemorySegment(key), MemorySegment.ofArray(storedValue));
}

public static byte[] getValueNotNullAsBytes(MemorySegment segment) {
return segment.asSlice(Long.BYTES).toArray(ValueLayout.JAVA_BYTE);
}

}
Loading
Loading