forked from tslab-hub/handlers
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathShrinkedList.cs
More file actions
88 lines (71 loc) · 1.81 KB
/
ShrinkedList.cs
File metadata and controls
88 lines (71 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections;
using System.Collections.Generic;
namespace TSLab.Script.Handlers
{
public sealed class ShrinkedList<T> : IList<T>
{
private readonly List<T> m_list;
public ShrinkedList(int capacity)
{
if (capacity < 1)
throw new ArgumentOutOfRangeException(nameof(capacity));
m_list = new List<T>(capacity);
}
public IEnumerator<T> GetEnumerator()
{
return m_list.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return m_list.GetEnumerator();
}
public void Add(T item)
{
if (m_list.Count == m_list.Capacity)
m_list.RemoveAt(0);
m_list.Add(item);
}
public void Clear()
{
m_list.Clear();
}
public bool Contains(T item)
{
return m_list.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
m_list.CopyTo(array, arrayIndex);
}
public bool Remove(T item)
{
return m_list.Remove(item);
}
public int Count
{
get { return m_list.Count; }
}
public bool IsReadOnly
{
get { return ((IList<T>)m_list).IsReadOnly; }
}
public int IndexOf(T item)
{
return m_list.IndexOf(item);
}
public void Insert(int index, T item)
{
m_list.Insert(index, item);
}
public void RemoveAt(int index)
{
m_list.RemoveAt(index);
}
public T this[int index]
{
get { return m_list[index]; }
set { m_list[index] = value; }
}
}
}