@SuppressWarnings("unchecked")
	private void insert(HashElement<T> val)
	{
		insertedElements++;		
		
		boolean found_spot = false;
		for(int i=0; i<this.table_hashes_used && !found_spot; i++)
		{
			// if it found an open available spot to place the element
			if(m_table[val.getHashValue().hash(i, m_table.length)] == null)
			{
				m_table[val.getHashValue().hash(i, m_table.length)] = val;
				val.getHashValue().setUsedHash(i);
				found_spot = true;
			}
		}
		
		// if a location was not found, we must rotate until a spot is available
		if(!found_spot)
		{
			HashElement<T> toInsert;
			HashElement<T> tmp = val;
			int c = 0;
			
			do
			{
				// setup to place in the next location
				toInsert = tmp;
				toInsert.getHashValue().increaseUsedHash(this.table_hashes_used);
				// grab the item in the location to insert to
				tmp = (HashElement<T>) m_table[toInsert.getHashValue().hash()% m_table.length];
				
				m_table[toInsert.getHashValue().hash()%m_table.length] = toInsert;
				c++;
			} while(tmp != null && !(tmp == val && c > 1000)); 
					//!(tmp == val && val.getHashValue().getUsedHash() > HashValue.get_hashCount()));
			
			if(tmp == val)
			{
				try {
					this.table_hashes_used++;
					insertedElements--;
					insert(val);
				} catch (Exception e) {
					e.printStackTrace();
					System.exit(0);
				}
			}
			else
			{
				cycle_count += 1;
			}
		}
	}