난 내 해시 테이블에 중복 항목 방지하기 위해 도움받을 수 있는지 궁금 :방지 중복 된 항목
bool hashmap::put(const stock& s, int& usedIndex, int& hashIndex, int& symbolHash)
{
hashIndex = this->hashStr(s.m_symbol); // Get remainder, Insert at that index.
symbolHash = (int&)s.m_symbol;
usedIndex = hashIndex;
while (hashTable[hashIndex].m_symbol != NULL) // collision found
{
++usedIndex %= maxSize; // if necessary wrap index around
if (hashTable[usedIndex].m_symbol == NULL)
{
hashTable[usedIndex] = s;
return true;
}
}
hashTable[hashIndex] = s; // insert if no collision
return true;
}
이 paramater에있는 HashIndex가에 삽입 할 적절한 인덱스를 생성하기 위해 자바 알고리즘을 사용을 표. usedIndex 매개 변수는 충돌이 발견 될 때 테이블에 삽입하는 곳입니다. symbolHash는 전달 된 이름의 주소를 가져옵니다. stock class는 클래스 객체입니다.
제 질문은 중복 된 항목을 어떻게 방지합니까?
정말 필요한가요? 다시 검색하는거야? – user40120
실제로 충돌하는 항목 만 확인하면됩니다. 너무 많으면 어쨌든 해시 테이블의 효율성이 떨어집니다. – jakber