Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.lang.visual-basic > #18561

Comportamento HashSet(Of T).Add()

Newsgroups it.comp.lang.visual-basic
Date 2015-11-11 09:14 -0800
Message-ID <c4445ca2-40fb-4806-b2d4-c7dbf89ea975@googlegroups.com> (permalink)
Subject Comportamento HashSet(Of T).Add()
From Antologiko <antologiko@gmail.com>

Show all headers | View raw


Buonasera a tutti.
Ho la seguente struttura dati

Private Structure Link
    Dim ParentID As Long
    Dim ChildID As Long

    Friend Sub New(ParentID As Long, ChildID As Long)
        Me.ParentID = ParentID
        Me.ChildID = ChildID
    End Sub
End Structure

Adesso definisco le variabili

Dim Links As HashSet(Of Link) = New HashSet(Of Link)
Dim P As Long = ... un valore qualsiasi
Dim C As Long = ... un valore qualsiasi
Dim L1 As Link = New Link(P, C)
Dim L2 As Link = New Link(P, C)
Dim B As Boolean

Dopodiché aggiungo i due link all'insieme

B = Links.Add(L1)
B = Links.Add(L2)

Nota: il metodo Add restituisce True solo se l'oggetto
viene aggiunto all'insieme, e questo accade solo se esso
non è già presente nell'insieme.

La domanda è: posso stare sicuro che per qualsiasi valore
dato a P e C, il secondo Add() restituirà False?

Od in altre parole, come viene calcolato l'hashcode per le
strutture come Link?

Back to it.comp.lang.visual-basic | Previous | Next | Find similar


Thread

Comportamento HashSet(Of T).Add() Antologiko <antologiko@gmail.com> - 2015-11-11 09:14 -0800

csiph-web