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%2FClusterMapSmall.java;h=334e1199134835166670c3608fba7e892d5f8b74;hp=c609560a7592ac1dea4631bb038af92c2f5c69d3;hb=e19c37f84fd1ce2d946578f7c05f3e45444ba67a;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterMapSmall.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterMapSmall.java index c609560a7..334e11991 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterMapSmall.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterMapSmall.java @@ -1,69 +1,69 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.db.procore.cluster; - -import gnu.trove.map.hash.TIntShortHashMap; - -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.impl.TableSizeListener; -import org.simantics.db.service.ClusterUID; -import org.simantics.db.service.ResourceUID; - -public class ClusterMapSmall { - private TableSizeListener sizeListener; - private ForeignTableSmall foreignTable; - //private TObjectIntHashMap hashMap; - private TIntShortHashMap hashMap; - public ClusterMapSmall(TableSizeListener sizeListener, ForeignTableSmall foreignTable) { - this.sizeListener = sizeListener; - this.foreignTable = foreignTable; - hashMap = null; - } - public ResourceUID getForeignResourceUID(short reference) { - assert(reference >>> 15 > 0); - short foreignIndex = (short)(reference ^ 1<<15); - return foreignTable.getResourceUID(foreignIndex); - } - public void compact() { - if(hashMap == null) return; - hashMap.compact(); - sizeListener.resized(); - } - public int getUsedSpace() { - if(hashMap == null) return 0; - int size = hashMap.size(); - int cap = hashMap.capacity(); - // int[], Object[], actual objects - return cap*(4+ObjectSizes.POINTER_SIZE)+size*ObjectSizes.ResourceUIDSize; - } - - public short getForeignReferenceOrCreateByResourceKey(int resourceKey, ClusterUID uid) throws DatabaseException { - if (null == hashMap) - hashMap = foreignTable.getResourceHashMap(); - short foreignIndex = hashMap.get(resourceKey); - if (0 == foreignIndex) { - if (hashMap.size() >= ClusterTraitsSmall.FOREIGN_INDEX_MAX) - throw new OutOfSpaceException("Out of space for foreign resources=" + hashMap.size()); - foreignIndex = foreignTable.createForeign(resourceKey, uid); - hashMap.put(resourceKey, foreignIndex); - } - return foreignIndex; - } - - public short getForeignReferenceOrZero(int resourceKey) throws DatabaseException { - if (null == hashMap) - hashMap = foreignTable.getResourceHashMap(); - return hashMap.get(resourceKey); - } - - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.procore.cluster; + +import gnu.trove.map.hash.TIntShortHashMap; + +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.impl.TableSizeListener; +import org.simantics.db.service.ClusterUID; +import org.simantics.db.service.ResourceUID; + +public class ClusterMapSmall { + private TableSizeListener sizeListener; + private ForeignTableSmall foreignTable; + //private TObjectIntHashMap hashMap; + private TIntShortHashMap hashMap; + public ClusterMapSmall(TableSizeListener sizeListener, ForeignTableSmall foreignTable) { + this.sizeListener = sizeListener; + this.foreignTable = foreignTable; + hashMap = null; + } + public ResourceUID getForeignResourceUID(short reference) { + assert(reference >>> 15 > 0); + short foreignIndex = (short)(reference ^ 1<<15); + return foreignTable.getResourceUID(foreignIndex); + } + public void compact() { + if(hashMap == null) return; + hashMap.compact(); + sizeListener.resized(); + } + public int getUsedSpace() { + if(hashMap == null) return 0; + int size = hashMap.size(); + int cap = hashMap.capacity(); + // int[], Object[], actual objects + return cap*(4+ObjectSizes.POINTER_SIZE)+size*ObjectSizes.ResourceUIDSize; + } + + public short getForeignReferenceOrCreateByResourceKey(int resourceKey, ClusterUID uid) throws DatabaseException { + if (null == hashMap) + hashMap = foreignTable.getResourceHashMap(); + short foreignIndex = hashMap.get(resourceKey); + if (0 == foreignIndex) { + if (hashMap.size() >= ClusterTraitsSmall.FOREIGN_INDEX_MAX) + throw new OutOfSpaceException("Out of space for foreign resources=" + hashMap.size()); + foreignIndex = foreignTable.createForeign(resourceKey, uid); + hashMap.put(resourceKey, foreignIndex); + } + return foreignIndex; + } + + public short getForeignReferenceOrZero(int resourceKey) throws DatabaseException { + if (null == hashMap) + hashMap = foreignTable.getResourceHashMap(); + return hashMap.get(resourceKey); + } + + +}