Changeset 393


Ignore:
Timestamp:
Dec 8, 2007, 11:16:57 PM (17 years ago)
Author:
イグトランス (egtra)
Message:

Dictionaryで、keyのGetHashCodeが負の値を返した場合でも問題なく動作するようにした。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/Classes/System/Collections/Generic/Dictionary.ab

    r366 r393  
    4040
    4141    Virtual Function Item(key As Key) As T
    42         Imports System.Collections.Generic.Detail
    43 
    4442        If Object.ReferenceEquals(key, Nothing) Then
    4543            'Throw ArgumentNullError
     
    4846        End If
    4947
    50         Dim hash = key.GetHashCode Mod al.Count
     48        Dim hash = getHash(key)
    5149        Dim a = al[hash] As ArrayList
    5250
     
    5452            Dim i As Long
    5553            For i = 0 To ELM(a.Count)
    56                 Dim pair = a[i] As Pair
     54                Dim pair = a[i] As Detail.Pair
    5755                If pair.Key.Equals(key) Then
    5856                    Return pair.Value
     
    6361        'KeyNotFoundException
    6462        Return Nothing
    65 
    6663    End Function
    6764
    6865    Virtual Sub Item(key As Key, value As T)
    69         Imports System.Collections.Generic.Detail
    70 
    7166        If Object.ReferenceEquals(key, Nothing) Then
    7267            'Throw ArgumentNullError
     
    7469        End If
    7570
    76         Dim hash = key.GetHashCode Mod al.Count
     71        Dim hash = getHash(key)
    7772        Dim a = al[hash] As ArrayList
    7873
     
    8378            Dim i As Long
    8479            For i = 0 To ELM(a.Count)
    85                 Dim pair = a[i] As Pair
     80                Dim pair = a[i] As Detail.Pair
    8681                If pair.Key.Equals(key) Then
    8782                    pair.Value = value
     
    9085        End If
    9186
    92         a.Add(New Pair(key, value))
     87        a.Add(New Detail.Pair(key, value))
    9388    End Sub
    9489
     
    108103    'Methods
    109104    Sub Add(key As Key, value As T)
    110         Imports System.Collections.Generic.Detail
    111 
    112105        If Object.ReferenceEquals(key, Nothing) Then
    113106            'Throw ArgumentNullError
     
    115108        End If
    116109
    117         Dim hash = key.GetHashCode Mod al.Count
     110        Dim hash = getHash(key)
    118111        Dim a = al[hash] As ArrayList
    119112
     
    124117            Dim i As Long
    125118            For i = 0 To ELM(a.Count)
    126                 Dim pair = a[i] As Pair
     119                Dim pair = a[i] As Detail.Pair
    127120                If pair.Key.Equals(key) Then
    128121                    'Throw ArgumentError
     
    131124        End If
    132125
    133         a.Add(New Pair(key, value))
     126        a.Add(New Detail.Pair(key, value))
    134127
    135         count ++
     128        count++
    136129    End Sub
    137130
     
    168161    Sub initialize(c As Long)
    169162        al = ArrayList.Repeat(Nothing, c)
    170         Dim e = al[0]
    171         Dim p = ObjPtr(e) As ULONG_PTR
    172 
    173163        count = 0
    174164    End Sub
     165
     166    Function getHash(key As Object) As Long
     167        Return (key.GetHashCode As DWord) Mod al.Count
     168    End Function
    175169
    176170    al As ArrayList
Note: See TracChangeset for help on using the changeset viewer.