5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.6-b27-fcs
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// Any modifications to this file will be lost upon recompilation of the source schema.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk// Generated on: 2012.06.11 at 10:34:07 AM PDT
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk//
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkpackage com.sun.identity.saml2.jaxb.assertion.impl.runtime;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * A set of {@link Object}s that uses the == (instead of equals)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * for the comparison.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @author
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkfinal class IdentityHashSet {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** The hash table data. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private Object table[];
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** The total number of mappings in the hash table. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private int count;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * The table is rehashed when its size exceeds this threshold. (The
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * value of this field is (int)(capacity * loadFactor).)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private int threshold;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** The load factor for the hashtable. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private static final float loadFactor = 0.3f;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private static final int initialCapacity = 191;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public IdentityHashSet() {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk table = new Object[initialCapacity];
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk threshold = (int) (initialCapacity * loadFactor);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public boolean contains(Object key) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Object tab[] = table;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int index = (System.identityHashCode(key) & 0x7FFFFFFF) % tab.length;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk while (true) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk final Object e = tab[index];
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (e == null)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (e==key)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk index = (index + 1) % tab.length;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * rehash.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * It is possible for one thread to call get method
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * while another thread is performing rehash.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Keep this in mind.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private void rehash() {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // create a new table first.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // meanwhile, other threads can safely access get method.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int oldCapacity = table.length;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Object oldMap[] = table;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int newCapacity = oldCapacity * 2 + 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Object newMap[] = new Object[newCapacity];
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (int i = oldCapacity; i-- > 0;)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (oldMap[i] != null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int index = (System.identityHashCode(oldMap[i]) & 0x7FFFFFFF) % newMap.length;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk while (newMap[index] != null)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk index = (index + 1) % newMap.length;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk newMap[index] = oldMap[i];
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // threshold is not accessed by get method.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk threshold = (int) (newCapacity * loadFactor);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // switch!
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk table = newMap;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public boolean add(Object newObj) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (count >= threshold)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk rehash();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Object tab[] = table;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int index = (System.identityHashCode(newObj) & 0x7FFFFFFF) % tab.length;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Object existing;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk while ((existing=tab[index]) != null) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(existing==newObj) return false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk index = (index + 1) % tab.length;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk tab[index] = newObj;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk count++;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk}