Skip to content

Package: KeyIntMap$BaseEntry

KeyIntMap$BaseEntry

nameinstructionbranchcomplexitylinemethod
KeyIntMap.BaseEntry(int, int)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3: *
4: * Copyright (c) 2004-2018 Oracle and/or its affiliates. All rights reserved.
5: *
6: * Oracle licenses this file to You under the Apache License, Version 2.0
7: * (the "License"); you may not use this file except in compliance with
8: * the License. You may obtain a copy of the License at
9: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package com.sun.xml.fastinfoset.util;
20: import com.sun.xml.fastinfoset.CommonResourceBundle;
21:
22: public abstract class KeyIntMap {
23: public static final int NOT_PRESENT = -1;
24:
25: /**
26: * The default initial capacity - MUST be a power of two.
27: */
28: static final int DEFAULT_INITIAL_CAPACITY = 16;
29:
30: /**
31: * The maximum capacity, used if a higher value is implicitly specified
32: * by either of the constructors with arguments.
33: * MUST be a power of two <= 1<<30.
34: */
35: static final int MAXIMUM_CAPACITY = 1 << 20;
36:
37: /**
38: * The load factor used when none specified in constructor.
39: **/
40: static final float DEFAULT_LOAD_FACTOR = 0.75f;
41:
42: int _readOnlyMapSize;
43:
44: /**
45: * The number of key-value mappings contained in this identity hash map.
46: */
47: int _size;
48:
49: int _capacity;
50:
51: /**
52: * The next size value at which to resize (capacity * load factor).
53: */
54: int _threshold;
55:
56: /**
57: * The load factor for the hash table.
58: */
59: final float _loadFactor;
60:
61: static class BaseEntry {
62: final int _hash;
63: final int _value;
64:
65: public BaseEntry(int hash, int value) {
66: _hash = hash;
67: _value = value;
68: }
69: }
70:
71: public KeyIntMap(int initialCapacity, float loadFactor) {
72: if (initialCapacity < 0)
73: throw new IllegalArgumentException(CommonResourceBundle.getInstance().
74: getString("message.illegalInitialCapacity", new Object[]{Integer.valueOf(initialCapacity)}));
75: if (initialCapacity > MAXIMUM_CAPACITY)
76: initialCapacity = MAXIMUM_CAPACITY;
77: if (loadFactor <= 0 || Float.isNaN(loadFactor))
78: throw new IllegalArgumentException(CommonResourceBundle.getInstance().
79: getString("message.illegalLoadFactor", new Object[]{Float.valueOf(loadFactor)}));
80:
81: // Find a power of 2 >= initialCapacity
82: if (initialCapacity != DEFAULT_INITIAL_CAPACITY) {
83: _capacity = 1;
84: while (_capacity < initialCapacity)
85: _capacity <<= 1;
86:
87: _loadFactor = loadFactor;
88: _threshold = (int)(_capacity * _loadFactor);
89: } else {
90: _capacity = DEFAULT_INITIAL_CAPACITY;
91: _loadFactor = DEFAULT_LOAD_FACTOR;
92: _threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
93: }
94: }
95:
96: public KeyIntMap(int initialCapacity) {
97: this(initialCapacity, DEFAULT_LOAD_FACTOR);
98: }
99:
100: public KeyIntMap() {
101: _capacity = DEFAULT_INITIAL_CAPACITY;
102: _loadFactor = DEFAULT_LOAD_FACTOR;
103: _threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
104: }
105:
106: public final int size() {
107: return _size + _readOnlyMapSize;
108: }
109:
110: public abstract void clear();
111:
112: public abstract void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear);
113:
114:
115: public static final int hashHash(int h) {
116: h += ~(h << 9);
117: h ^= (h >>> 14);
118: h += (h << 4);
119: h ^= (h >>> 10);
120: return h;
121: }
122:
123: public static final int indexFor(int h, int length) {
124: return h & (length-1);
125: }
126:
127: }