root/lang/vb2005/FuwaKumo/trunk/FuwaKumo/SortedSizedList.vb @ 34124

Revision 33861, 0.9 kB (checked in by kiri_feather, 6 years ago)
Line 
1Public Class SortedSizedList(Of TKey, TValue)
2    Inherits SortedList(Of TKey, TValue)
3
4    Private _size As Integer = 200
5
6    Public Sub New()
7
8    End Sub
9
10    Public Sub New(ByVal capacity As Integer)
11        _size = capacity
12    End Sub
13
14    Public Shadows Sub Add(ByVal key As TKey, ByVal value As TValue)
15        MyBase.Add(key, value)
16        Truncate()
17    End Sub
18
19    Public Property Size() As Integer
20        Get
21            If _size = Integer.MaxValue Then
22                Return 0
23            Else
24                Return _size
25            End If
26        End Get
27        Set(ByVal value As Integer)
28            If value = 0 Then value = Integer.MaxValue
29            _size = value
30            Truncate()
31        End Set
32    End Property
33
34    Private Sub Truncate()
35        Do While Me.Count > _size
36            Me.RemoveAt(0)
37        Loop
38    End Sub
39End Class
Note: See TracBrowser for help on using the browser.