Skip to content

Commit

Permalink
Merge pull request #606 from 47degrees/fix/v3-v5-generation
Browse files Browse the repository at this point in the history
  • Loading branch information
gutiory authored Oct 18, 2022
2 parents b86738f + 164452d commit 54a5990
Show file tree
Hide file tree
Showing 6 changed files with 814 additions and 772 deletions.
106 changes: 53 additions & 53 deletions modules/memeid/src/main/java/memeid/Bits.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,75 +26,75 @@
*/
public final class Bits {

/* Convert to a byte array from a Long. */
public static byte[] toBytes(final long x) {
return new byte[]{
(byte) (x >> 56), (byte) (x >> 48), (byte) (x >> 40), (byte) (x >> 32),
(byte) (x >> 24), (byte) (x >> 16), (byte) (x >> 8), (byte) x
};
}
/* Convert to a byte array from a Long. */
public static byte[] toBytes(final long x) {
return new byte[] { (byte) (x >> 56), (byte) (x >> 48), (byte) (x >> 40), (byte) (x >> 32), (byte) (x >> 24),
(byte) (x >> 16), (byte) (x >> 8), (byte) x };
}

/* Convert to a Long from a byte seq. */
public static long fromBytes(final byte[] bytes) {
assert bytes.length == 8 : "data must be 8 bytes in length";
/* Convert to a Long from a byte seq. */
public static long fromBytes(final byte[] bytes) {
assert bytes.length == 8 : "data must be 8 bytes in length";

long l = 0;
long l = 0;

for (byte aByte : bytes) {
l <<= 8;
l |= aByte & 0xFF;
}
for (byte aByte : bytes) {
l <<= 8;
l |= aByte & 0xFF;
}

return l;
}
return l;
}

/* Read the byte(s) from `num` specified by the `bitmask`. */
public static long readByte(final long bitmask, final long num) {
final long off = maskOffset(bitmask);
/* Read the byte(s) from `num` specified by the `bitmask`. */
public static long readByte(final long bitmask, final long num) {
final long off = maskOffset(bitmask);

return (bitmask >>> off) & (num >>> off);
}
return (bitmask >>> off) & (num >>> off);
}

public static long readByte(final long bitmask, final long offset, final long num) {
return (bitmask >>> offset) & (num >>> offset);
}
public static long readByte(final long bitmask, final long offset, final long num) {
return (bitmask >>> offset) & (num >>> offset);
}

/* Write the byte(s) from `value` in `num` using the given `bitmask`. */
public static long writeByte(final long bitmask, final long num, final long value) {
return (num & ~bitmask) | (bitmask & value << maskOffset(bitmask));
}
/* Write the byte(s) from `value` in `num` using the given `bitmask`. */
public static long writeByte(final long bitmask, final long num, final long value) {
return (num & ~bitmask) | (bitmask & value << maskOffset(bitmask));
}

/* Write the byte(s) from `value` in `num` using the given `bitmask`. */
public static long writeByte(final long bitmask, final long offset, final long num, final long value) {
return (num & ~bitmask) | (bitmask & value << offset);
}
/* Write the byte(s) from `value` in `num` using the given `bitmask`. */
public static long writeByte(final long bitmask, final long offset, final long num, final long value) {
return (num & ~bitmask) | (bitmask & value << offset);
}

/* Given a bitmask, retrieve its `offset`. */
private static long maskOffset(long mask) {
if (mask == 0 || mask == -1) return 0;
else if (mask < 0) {
final long next = -(mask + 1);
/* Given a bitmask, retrieve its `offset`. */
private static long maskOffset(long mask) {
if (mask == 0 || mask == -1)
return 0;
else if (mask < 0) {
final long next = -(mask + 1);

long offset = offset(next);
long offset = offset(next);

long res = 0;
long res = 0;

while ((1L & (next >> offset >> res)) != 0) {
res++;
}
while ((1L & (next >> offset >> res)) != 0) {
res++;
}

return 64 - (64 - res);
} else return offset(mask);
}
return 64 - (64 - res);
} else
return offset(mask);
}

private static long offset(long x) {
long res = 0;
private static long offset(long x) {
long res = 0;

while ((1L & (x >> res)) <= 0) {
res++;
}
while ((1L & (x >> res)) <= 0) {
res++;
}

return res;
}
return res;
}

}
23 changes: 12 additions & 11 deletions modules/memeid/src/main/java/memeid/Mask.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@

public final class Mask {

public static final long MASKS_56 = 0xFF00000000000000L;
public static final long MASKS_48 = 0xFF000000000000L;
public static final long MASKS_56 = 0xFF00000000000000L;
public static final long MASKS_48 = 0xFF000000000000L;
public static final long MASKS_64 = 0x8000000000000000L;

public final static long TIME_LOW = 0xFFFFFFFFL;
public final static long TIME_MID = 0xFFFF00000000L;
public final static long TIME_HIGH = 0xFFF000000000000L;
public final static long TIME_LOW = 0xFFFFFFFFL;
public final static long TIME_MID = 0xFFFF00000000L;
public final static long TIME_HIGH = 0xFFF000000000000L;

public final static long CLOCK_SEQ_LOW = 0xFFL;
public final static long CLOCK_SEQ_HIGH = 0x3F00L;
public final static long CLOCK_SEQ_LOW = 0xFFL;
public final static long CLOCK_SEQ_HIGH = 0x3F00L;

public final static long UB32 = 0xFFFFFFFFL;
public final static long UB32 = 0xFFFFFFFFL;

public final static long HASHED = 0x30000000000000L;
public final static long HASHED = 0xC000000000000000L;

public final static long V4_LSB = 0xC000000000000000L;
public final static long V4_LSB = 0xC000000000000000L;

public final static long VERSION = 0xF000L;
public final static long VERSION = 0xF000L;
}
22 changes: 11 additions & 11 deletions modules/memeid/src/main/java/memeid/Offset.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

public final class Offset {

public final static long OFFSET_56 = 56L;
public final static long OFFSET_48 = 48L;
public final static long OFFSET_56 = 56L;
public final static long OFFSET_48 = 48L;

public final static long TIME_LOW = 0L;
public final static long TIME_MID = 32L;
public final static long TIME_HIGH = 48L;
public final static long TIME_LOW = 0L;
public final static long TIME_MID = 32L;
public final static long TIME_HIGH = 48L;

public final static long CLOCK_SEQ_LOW = 0L;
public final static long CLOCK_SEQ_HIGH = 8L;
public final static long CLOCK_SEQ_LOW = 0L;
public final static long CLOCK_SEQ_HIGH = 8L;

public final static long HASHED = 52L;
public final static long HASHED = 62L;

public final static long V4_LSB = 62L;
public final static long V4_LSB = 62L;

public final static long VERSION = 12L;

public final static long VERSION = 12L;

}
Loading

0 comments on commit 54a5990

Please sign in to comment.