/******************************************************************************* * 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 org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.db.impl.ClusterI; import org.simantics.db.impl.IntAllocatorI; import org.simantics.db.impl.Modifier; import org.simantics.db.impl.ResourceImpl; import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.procedure.AsyncContextMultiProcedure; import org.simantics.db.procedure.AsyncMultiProcedure; final class TableIntArraySet { public static final int HeaderSize = 1; private static final int SIZE_OFFSET = -1; static int create(final int[] ints, IntAllocatorI allocator) throws DatabaseException { final int LENGTH = ints.length*2; if (LENGTH <1) throw new DatabaseException("Illegal argument to create TableIntArraySet."); int newBase = allocator.allocate(LENGTH + HeaderSize) + HeaderSize; int[] table = allocator.getTable(); table[newBase + SIZE_OFFSET] = -LENGTH; for (int i=0; i 0); Ints it = new Ints(); int i; for (i=0; i 0); it.ints = new int[size+1]; for (i=0; i 0); int i; for (i=0; i 0); int i; for (i=0; ii; --end) if (0 != table[base + end]) break; table[base + i] = table[base + end]; table[base + end] = 0; return end; } static int removeIntLast(int[] table, int base) throws DatabaseException { final int size = getSize(table, base); if (size != 1) throw new DatabaseException("Illegal call of TableIntArraySet.removeLastint"); int t = table[base]; table[base] = 0; return t; } static int getSize(int[] table, int base) { final int size = -table[base + SIZE_OFFSET]; assert(size > 0); int i; for (i=0; i0); return size + HeaderSize; } static void foreachInt(final int[] table, final int base, ReadGraphImpl graph, AsyncMultiProcedure procedure, Modifier modifier) throws DatabaseException { final int size = -table[base + SIZE_OFFSET]; assert(size>0); for (int i=0; i void foreachInt(final int[] table, final int base, ReadGraphImpl graph, C context, AsyncContextMultiProcedure procedure, Modifier modifier) throws DatabaseException { final int size = -table[base + SIZE_OFFSET]; assert(size>0); for (int i=0; i0); for (int i=0; i boolean foreachInt(final int[] table, final int base , final ClusterI.ObjectProcedure procedure, final Context context, final Modifier modifier) throws DatabaseException { final int size = -table[base + SIZE_OFFSET]; assert(size>0); for (int i=0; i