1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.utils.datastructures.map;
16 * Description associativity of dimensions.
17 * The maximum number of dimensions is 32.
19 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
21 public final class Associativity {
23 public static Associativity of(boolean...dimensionAssociativity)
25 return new Associativity(dimensionAssociativity);
28 public static Associativity[] fullAssociativity(int level)
30 int count = (1 << level)-1;
31 Associativity[] result = new Associativity[count];
32 for (int i=0; i<count; i++)
33 result[i] = new Associativity(level, i);
37 public int dimensionAssociativity;
40 public Associativity(boolean...dimensionAssociativity)
42 if (dimensionAssociativity==null || dimensionAssociativity.length>32)
43 throw new IllegalArgumentException();
46 for (boolean b : dimensionAssociativity) {
47 if (b) this.dimensionAssociativity |= mask;
51 level = dimensionAssociativity.length;
53 public Associativity(int level, int dimensionAssociativity)
55 this.dimensionAssociativity = dimensionAssociativity;
60 public int hashCode() {
61 return dimensionAssociativity;
65 public boolean equals(Object obj) {
66 if (obj == null) return false;
67 if (!(obj.getClass().equals(this.getClass()))) return false;
68 Associativity other = (Associativity) obj;
69 return dimensionAssociativity == other.dimensionAssociativity;
72 public int getLevel() {