001: //
002: // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.5-b16-fcs
003: // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
004: // Any modifications to this file will be lost upon recompilation of the source schema.
005: // Generated on: 2005.12.17 at 09:43:27 AM GMT+07:00
006: //
007:
008: package com.mvnforum.jaxb.db.impl.runtime;
009:
010: /**
011: * A set of {@link Object}s that uses the == (instead of equals)
012: * for the comparison.
013: *
014: * @author
015: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
016: */
017: final class IdentityHashSet {
018: /** The hash table data. */
019: private Object table[];
020:
021: /** The total number of mappings in the hash table. */
022: private int count;
023:
024: /**
025: * The table is rehashed when its size exceeds this threshold. (The
026: * value of this field is (int)(capacity * loadFactor).)
027: */
028: private int threshold;
029:
030: /** The load factor for the hashtable. */
031: private static final float loadFactor = 0.3f;
032: private static final int initialCapacity = 191;
033:
034: public IdentityHashSet() {
035: table = new Object[initialCapacity];
036: threshold = (int) (initialCapacity * loadFactor);
037: }
038:
039: public boolean contains(Object key) {
040: Object tab[] = table;
041: int index = (System.identityHashCode(key) & 0x7FFFFFFF)
042: % tab.length;
043:
044: while (true) {
045: final Object e = tab[index];
046: if (e == null)
047: return false;
048: if (e == key)
049: return true;
050: index = (index + 1) % tab.length;
051: }
052: }
053:
054: /**
055: * rehash.
056: *
057: * It is possible for one thread to call get method
058: * while another thread is performing rehash.
059: * Keep this in mind.
060: */
061: private void rehash() {
062: // create a new table first.
063: // meanwhile, other threads can safely access get method.
064: int oldCapacity = table.length;
065: Object oldMap[] = table;
066:
067: int newCapacity = oldCapacity * 2 + 1;
068: Object newMap[] = new Object[newCapacity];
069:
070: for (int i = oldCapacity; i-- > 0;)
071: if (oldMap[i] != null) {
072: int index = (System.identityHashCode(oldMap[i]) & 0x7FFFFFFF)
073: % newMap.length;
074: while (newMap[index] != null)
075: index = (index + 1) % newMap.length;
076: newMap[index] = oldMap[i];
077: }
078:
079: // threshold is not accessed by get method.
080: threshold = (int) (newCapacity * loadFactor);
081: // switch!
082: table = newMap;
083: }
084:
085: public boolean add(Object newObj) {
086: if (count >= threshold)
087: rehash();
088:
089: Object tab[] = table;
090: int index = (System.identityHashCode(newObj) & 0x7FFFFFFF)
091: % tab.length;
092:
093: Object existing;
094:
095: while ((existing = tab[index]) != null) {
096: if (existing == newObj)
097: return false;
098: index = (index + 1) % tab.length;
099: }
100: tab[index] = newObj;
101:
102: count++;
103:
104: return true;
105: }
106: }
|