X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fprocore%2Fcluster%2FBitUtility.java;fp=bundles%2Forg.simantics.db.procore%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fprocore%2Fcluster%2FBitUtility.java;h=8e47ae8dd9546925f5265f350e2482521d04549e;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/BitUtility.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/BitUtility.java new file mode 100644 index 000000000..8e47ae8dd --- /dev/null +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/BitUtility.java @@ -0,0 +1,58 @@ +package org.simantics.db.procore.cluster; + +final class BitUtility { + static final long LongBits = 64; + static final int IntBits = 32; + static final short ShortBits = 16; + static final long ClearHighIntMask = (1L << IntBits) - 1; + static final long ClearLowIntMask = -1l ^ ClearHighIntMask; + static final long ClearHighShortMask = (1L << ShortBits) - 1; + static final long ClearLowShortMask = -1L ^ ClearHighShortMask; + + static final int getHighInt(long longValue) { + return (int) (longValue >>> IntBits); + } + + static final long setHighInt(long longValue, int highValue) { + longValue = (longValue & ClearHighIntMask) | (long) highValue << IntBits; + return longValue; + } + + static final int getLowInt(long longValue) { + return (int) longValue; + } + + static final long setLowInt(long longValue, int lowValue) { + longValue = (longValue & ClearLowIntMask) | lowValue; + return longValue; + } + + static final long setLowAndHighInt(long longValue, int lowValue, int highValue) { + longValue = ((long) lowValue & ClearHighIntMask) | ((long) highValue << IntBits); + return longValue; + } + + static final short getLowShort(long longValue) { + return (short)longValue; + } + + static final long setLowShort(long longValue, short lowValue) { + longValue = (longValue & ClearLowShortMask) | (lowValue & ClearHighShortMask); + return longValue; + } + + static final int getMiddle(final long longValue, final int skip, final int size) { + return (int)(longValue >>> skip) & (1<