]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/BitUtility.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.procore / src / org / simantics / db / procore / cluster / BitUtility.java
1 package org.simantics.db.procore.cluster;\r
2 \r
3 final class BitUtility {\r
4         static final long LongBits = 64;\r
5         static final int IntBits = 32;\r
6     static final short ShortBits = 16;\r
7     static final long ClearHighIntMask = (1L << IntBits) - 1;\r
8     static final long ClearLowIntMask = -1l ^ ClearHighIntMask;\r
9     static final long ClearHighShortMask = (1L << ShortBits) - 1;\r
10     static final long ClearLowShortMask  = -1L ^ ClearHighShortMask;\r
11 \r
12     static final int getHighInt(long longValue) {\r
13         return (int) (longValue >>> IntBits);\r
14     }\r
15 \r
16     static final long setHighInt(long longValue, int highValue) {\r
17         longValue = (longValue & ClearHighIntMask) | (long) highValue << IntBits;\r
18         return longValue;\r
19     }\r
20 \r
21     static final int getLowInt(long longValue) {\r
22         return (int) longValue;\r
23     }\r
24 \r
25     static final long setLowInt(long longValue, int lowValue) {\r
26         longValue = (longValue & ClearLowIntMask) | lowValue;\r
27         return longValue;\r
28     }\r
29 \r
30     static final long setLowAndHighInt(long longValue, int lowValue, int highValue) {\r
31         longValue = ((long) lowValue & ClearHighIntMask) | ((long) highValue << IntBits);\r
32         return longValue;\r
33     }\r
34 \r
35     static final short getLowShort(long longValue) {\r
36         return (short)longValue;\r
37     }\r
38 \r
39     static final long setLowShort(long longValue, short lowValue) {\r
40         longValue = (longValue & ClearLowShortMask) | (lowValue & ClearHighShortMask);\r
41         return longValue;\r
42     }\r
43 \r
44     static final int getMiddle(final long longValue, final int skip, final int size) {\r
45         return (int)(longValue >>> skip) & (1<<size)-1;\r
46     }\r
47 \r
48     static final long setMiddle(long longValue, final int skip, final int size, int value) {\r
49         long a1 = (1L<<size)-1;\r
50         long m1 = (a1 << skip);\r
51         long mask = -1L ^ m1;\r
52         long t1 = (value & a1) << skip;\r
53         long t2 = longValue & mask;\r
54         long t3 = t2 | t1;\r
55         return t3;\r
56     }\r
57 \r
58 }\r