Package org.getspout.spoutapi.util.map

Source Code of org.getspout.spoutapi.util.map.TByteTripleFloatHashMap

/*
* This file is part of SpoutcraftPlugin.
*
* Copyright (c) 2011 SpoutcraftDev <http://spoutcraft.org//>
* SpoutcraftPlugin is licensed under the GNU Lesser General Public License.
*
* SpoutcraftPlugin is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SpoutcraftPlugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.getspout.spoutapi.util.map;

import gnu.trove.TFloatCollection;
import gnu.trove.iterator.TIntFloatIterator;
import gnu.trove.map.hash.TIntFloatHashMap;
import gnu.trove.set.TIntSet;

/**
* A simplistic map that supports a 3 bytes for keys, using a trove int float hashmap in the backend.
*/
public class TByteTripleFloatHashMap {
  private TIntFloatHashMap map;

  public TByteTripleFloatHashMap() {
    map = new TIntFloatHashMap(100);
  }

  public TByteTripleFloatHashMap(int capacity) {
    map = new TIntFloatHashMap(capacity);
  }

  public float put(byte key1, byte key2, byte key3, float value) {
    int key = key(key1, key2, key3);
    return map.put(key, value);
  }

  public float get(byte key1, byte key2, byte key3) {
    int key = key(key1, key2, key3);
    return map.get(key);
  }

  public boolean containsKey(byte key1, byte key2, byte key3) {
    int key = key(key1, key2, key3);
    return map.containsKey(key);
  }

  public void clear() {
    map.clear();
  }

  public boolean containsValue(float val) {
    return map.containsValue(val);
  }

  public boolean increment(byte key1, byte key2, byte key3) {
    int key = key(key1, key2, key3);
    return map.increment(key);
  }

  public boolean isEmpty() {
    return map.isEmpty();
  }

  public TIntFloatIterator iterator() {
    return map.iterator();
  }

  public TIntSet keySet() {
    return map.keySet();
  }

  public int[] keys() {
    return map.keys();
  }

  public float remove(byte key1, byte key2, byte key3) {
    int key = key(key1, key2, key3);
    return map.remove(key);
  }

  public int size() {
    return map.size();
  }

  public TFloatCollection valueCollection() {
    return map.valueCollection();
  }

  public float[] values() {
    return map.values();
  }

  private static final int key(int x, int y, int z) {
    return (x & 0xF) << 11 | (z & 0xF) << 7 | (y & 0x7F);
  }
}
TOP

Related Classes of org.getspout.spoutapi.util.map.TByteTripleFloatHashMap

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.