931db162259b162bebbf7a5ed196dd16120b93ff
[yangtools.git] / third-party / triemap / src / main / java / org / opendaylight / yangtools / triemap / Constants.java
1 /*
2  * (C) Copyright 2017 Pantheon Technologies, s.r.o. and others.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.opendaylight.yangtools.triemap;
17
18 import static com.google.common.base.Verify.verify;
19
20 import com.google.common.math.IntMath;
21 import java.math.RoundingMode;
22
23 /**
24  * Various implementation-specific constants shared across classes.
25  *
26  * @author Robert Varga
27  */
28 final class Constants {
29     private Constants() {
30         throw new UnsupportedOperationException();
31     }
32
33     /**
34      * Size of the hash function, in bits.
35      */
36     static final int HASH_BITS = Integer.SIZE;
37
38     /**
39      * Size of the CNode bitmap, in bits.
40      */
41     static final int BITMAP_BITS = Integer.SIZE;
42
43     /**
44      * Number of hash bits consumed in each CNode level.
45      */
46     static final int LEVEL_BITS = 5;
47
48     /**
49      * Maximum depth of a TrieMap.
50      */
51     static final int MAX_DEPTH = 7;
52
53     static {
54         verify(LEVEL_BITS == IntMath.log2(BITMAP_BITS, RoundingMode.UNNECESSARY));
55         verify(MAX_DEPTH == IntMath.divide(HASH_BITS, LEVEL_BITS, RoundingMode.CEILING));
56     }
57 }