|
Groovy example source code file (AbstractConcurrentDoubleKeyMap.java)
The Groovy AbstractConcurrentDoubleKeyMap.java source code
/*
* Copyright 2003-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.groovy.util;
public abstract class AbstractConcurrentDoubleKeyMap<K1,K2,V> extends AbstractConcurrentMapBase {
public AbstractConcurrentDoubleKeyMap(Object segmentInfo) {
super(segmentInfo);
}
static <K1,K2> int hash(K1 key1, K2 key2) {
int h = 31*key1.hashCode() + key2.hashCode();
h += ~(h << 9);
h ^= (h >>> 14);
h += (h << 4);
h ^= (h >>> 10);
return h;
}
public V get(K1 key1, K2 key2) {
int hash = hash(key1, key2);
return segmentFor(hash).get(key1, key2, hash);
}
public Entry<K1,K2,V> getOrPut(K1 key1, K2 key2, V value) {
int hash = hash(key1,key2);
return segmentFor(hash).getOrPut(key1, key2, hash, value);
}
public void put(K1 key1, K2 key2, V value) {
int hash = hash(key1, key2);
segmentFor(hash).put(key1, key2, hash).setValue(value);
}
public void remove(K1 key1, K2 key2) {
int hash = hash(key1, key2);
segmentFor(hash).remove(key1, key2, hash);
}
public final Segment<K1,K2,V> segmentFor(int hash) {
return (Segment<K1,K2,V>) segments[(hash >>> segmentShift) & segmentMask];
}
abstract static class Segment<K1,K2,V> extends AbstractConcurrentMapBase.Segment {
Segment(int initialCapacity) {
super(initialCapacity);
}
V get(K1 key1, K2 key2, int hash) {
Object[] tab = table;
Object o = tab[hash & (tab.length - 1)];
if (o != null) {
if (o instanceof Entry) {
Entry<K1,K2,V> e = (Entry
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy AbstractConcurrentDoubleKeyMap.java source code file: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.