source: trunk/Include/Classes/System/Collections/Generic/Dictionary.ab@ 311

Last change on this file since 311 was 311, checked in by イグトランス (egtra), 17 years ago

コンパイルできないものをコミットしてしまったのでコミットのやりなおし

File size: 3.8 KB
Line 
1'Classes/System/Collections/Generic/Dictionary.ab
2
3'#require <Classes/System/Collections/Generic/EqualityComparer.ab>
4
5Namespace System
6Namespace Collections
7Namespace Generic
8
9Namespace Detail
10 Class Pair
11 Public
12 Sub Pair(key As Object, value As Object)
13 Key = key
14 Value = value
15 End Sub
16
17 Key As Object
18 Value As Object
19 End Class
20End Namespace 'Detail
21
22Class Dictionary<Key, T>
23Public
24 'Constructor
25 Sub Dictionary()
26 initialize(23)
27 End Sub
28' Sub Dictionary(d As IDictionary<Key, T>)
29' Sub Dictionary(comparer As IEqualityComparer<Key>)
30 Sub Dictionary(capacity As Long)
31 initialize(capacity)
32 End Sub
33' Sub Dictionary(d As IDictionary<Key, T>, comparer As IEqualityComparer<Key>)
34' Sub Dictionary(capacity As Long, comparer As IEqualityComparer<Key>)
35
36 'Properties
37' Function Comparer() As IEqualityComparer<Key>
38' Virtual Function Count() As Long
39' End Function
40
41' Virtual Function Item(key As Key) As T
42 Virtual Function Item(key As Key) As Object
43 Imports System.Collections.Generic.Detail
44
45 If Object.ReferenceEquals(key, Nothing) Then
46 'Throw ArgumentNullError
47 Exit Sub
48 End If
49
50 Dim hash = key.GetHashCode Mod al.Count
51 Dim a = al[hash] As ArrayList
52
53 If Not Object.ReferenceEquals(a, Nothing) Then
54 Dim i As Long
55 For i = 0 To ELM(a.Count)
56 Dim pair = a[i] As Pair
57 If pair.Key.Equals(key) Then
58 Return pair.Value
59 End If
60 Next
61 End If
62 'KeyNotFoundException
63 Return Nothing
64
65 End Function
66
67 Virtual Sub Item(key As Key, value As T)
68 Imports System.Collections.Generic.Detail
69
70 If Object.ReferenceEquals(key, Nothing) Then
71 'Throw ArgumentNullError
72 Exit Sub
73 End If
74
75 Dim hash = key.GetHashCode Mod al.Count
76 Dim a = al[hash] As ArrayList
77
78 If Object.ReferenceEquals(a, Nothing) Then
79 a = New ArrayList
80 al[hash] = a
81 Else
82 Dim i As Long
83 For i = 0 To ELM(a.Count)
84 Dim pair = a[i] As Pair
85 If pair.Key.Equals(key) Then
86 pair.Value = value
87 End If
88 Next
89 End If
90
91 a.Add(New Pair(key, value))
92 End Sub
93
94' Function Keys() As KeyCollection
95' Function Values() As ValuesCollection
96/*
97 'Operators
98' Function Operator [](key As Key) As T
99 Function Operator [](key As Key) As Object
100 Return Item[key]
101 End Function
102
103 Sub Operator []=(key As Key, value As T)
104' Item[key] = vaule
105 End Sub
106*/
107 'Methods
108 Sub Add(key As Key, value As T)
109 Imports System.Collections.Generic.Detail
110
111 If Object.ReferenceEquals(key, Nothing) Then
112 'Throw ArgumentNullError
113 Exit Sub
114 End If
115
116 Dim hash = key.GetHashCode Mod al.Count
117 Dim a = al[hash] As ArrayList
118
119 If Object.ReferenceEquals(a, Nothing) Then
120 a = New ArrayList
121 al[hash] = a
122 Else
123 Dim i As Long
124 For i = 0 To ELM(a.Count)
125 Dim pair = a[i] As Pair
126 If pair.Key.Equals(key) Then
127 'Throw ArgumentError
128 End If
129 Next
130 End If
131
132 a.Add(New Pair(key, value))
133 End Sub
134
135 Sub Clear()
136 Dim i As Long
137 For i = 0 To ELM(al.Count)
138 al[i] = Nothing
139 Next
140 End Sub
141
142' Function ContainsKey(key As Key) As Boolean
143' End Function
144' Function ContainsValue(value As T) As Boolean
145' End Function
146' Function GetEnumerator() As Enumerator
147' Function Remove(key As Key) As Boolean
148' End Function
149' Function TryGetValue(key As Key, ByRef value As T) As Boolean
150' End Function
151
152 'Classses
153' Class KeyCollection
154' Class ValuesCollection
155' Class Enumerator
156
157Private
158
159' comp As System.Collections.Generic.Detail.DefaultEqualityComparer<Key> 'IEqualityComparer<Key>
160
161 Sub initialize(c As Long)
162 al = ArrayList.Repeat(Nothing, c)
163 Dim e = al[0]
164 Dim p = ObjPtr(e) As ULONG_PTR
165 OutputDebugString(ToTCStr(Str$(p)))
166 End Sub
167
168 al As ArrayList
169
170End Class
171
172End Namespace 'Generic
173End Namespace 'Collections
174End Namespace 'System
Note: See TracBrowser for help on using the repository browser.