///
/// Checks if this hashset contains the item
///
///
item to check for containment
/// true if item contained; false if not
public bool Contains(T item) {
if (m_buckets != null) {
int hashCode = InternalGetHashCode(item);
// see note at "HashSet" level describing why "- 1" appears in for loop
for (int i = m_buckets[hashCode % m_buckets.Length] - 1; i >= 0; i = m_slots[i].next) {
if (m_slots[i].hashCode == hashCode && m_comparer.Equals(m_slots[i].value, item)) {
return true;
}
}
}
// either m_buckets is null or wasn't found
return false;
}
И я много где читал: «Сложность поиска в хэш-наборе равна O(1)». Как?
Тогда почему существует этот цикл for?
Изменить: ссылка на .net: https://github.com/microsoft/references ... ter/System .Core/System/Collections/Generic/HashSet.cs
[code]HashSet.Contains[/code] реализация в .Net: [code] /// /// Checks if this hashset contains the item /// /// item to check for containment /// true if item contained; false if not public bool Contains(T item) { if (m_buckets != null) { int hashCode = InternalGetHashCode(item); // see note at "HashSet" level describing why "- 1" appears in for loop for (int i = m_buckets[hashCode % m_buckets.Length] - 1; i >= 0; i = m_slots[i].next) { if (m_slots[i].hashCode == hashCode && m_comparer.Equals(m_slots[i].value, item)) { return true; } } } // either m_buckets is null or wasn't found return false; } [/code] И я много где читал: «Сложность поиска в хэш-наборе равна O(1)». Как? Тогда почему существует этот цикл for? Изменить: ссылка на .net: https://github.com/microsoft/referencesource/blob/master/System .Core/System/Collections/Generic/HashSet.cs