@Override public Entry getBucket(Object object) { final int hashCode = this.comparator.hashCodeOf( object ); final int index = indexOf( hashCode, this.table.length ); return this.table[index]; }
public Triple get(final Triple triple) { final int hashCode = this.comparator.hashCodeOf( triple ); final int index = indexOf( hashCode, this.table.length ); // scan the linked entries to see if it exists TripleImpl current = (TripleImpl) this.table[index]; while ( current != null ) { if ( hashCode == this.comparator.hashCodeOf( current ) && this.comparator.equal( triple, current ) ) { return current; } current = (TripleImpl) current.getNext(); } return null; }
public boolean contains( final Triple triple ) { final int hashCode = this.comparator.hashCodeOf( triple ); final int index = indexOf( hashCode, this.table.length ); // scan the linked entries to see if it exists TripleImpl current = (TripleImpl) this.table[index]; while ( current != null ) { if ( hashCode == this.comparator.hashCodeOf( current ) ) { if ( this.comparator.equal( triple, current ) ) { return true; } } current = (TripleImpl) current.getNext(); } return false; }
public boolean remove(final Triple triple) { final int hashCode = this.comparator.hashCodeOf( triple ); final int index = indexOf( hashCode, this.table.length ); TripleImpl previous = (TripleImpl) this.table[index]; TripleImpl current = previous; Triple key = new TripleImpl( triple.getInstance(), triple.getProperty(), Variable.v ); while ( current != null ) { final TripleImpl next = (TripleImpl) current.getNext(); if ( hashCode == this.comparator.hashCodeOf( current ) && this.comparator.equal( key, current ) ) { if ( ( current.getValue() == null && triple.getValue() == null ) || ( current.getValue() != null && current.getValue().equals( triple.getValue() ) ) ) { if ( previous == current ) { this.table[index] = next; } else { previous.setNext( next ); } current.setNext( null ); this.size--; return true; } } previous = current; current = next; } return false; }
public boolean put(final Triple triple, final boolean checkExists) { final int hashCode = this.comparator.hashCodeOf( triple ); final int index = indexOf( hashCode, this.table.length ); // scan the linked entries to see if it exists if ( checkExists ) { Object val = triple.getValue(); ((TripleImpl) triple).setValue( Variable.v ); TripleImpl current = (TripleImpl) this.table[index]; while ( current != null ) { if ( hashCode == this.comparator.hashCodeOf( current ) && this.comparator.equal( triple, current ) ) { current.setValue( val ); return true; } current = (TripleImpl) current.getNext(); } ((TripleImpl) triple).setValue( val ); } // We aren't checking the key exists, or it didn't find the key TripleImpl timpl = ( TripleImpl ) triple; timpl.setNext( this.table[index] ); this.table[index] = timpl; if ( this.size++ >= this.threshold ) { resize( 2 * this.table.length ); } return false; }