blob: cceab62bfb194c35cb3830602582ade81a8e6145 (
plain)
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
|
using System;
using System.Collections.Generic;
namespace ARMeilleure.Common
{
public class SortedIntegerList
{
private List<int> _items;
public int Count => _items.Count;
public int this[int index]
{
get
{
return _items[index];
}
set
{
_items[index] = value;
}
}
public SortedIntegerList()
{
_items = new List<int>();
}
public bool Add(int value)
{
if (_items.Count == 0 || value > Last())
{
_items.Add(value);
return true;
}
else
{
int index = _items.BinarySearch(value);
if (index >= 0)
{
return false;
}
_items.Insert(-1 - index, value);
return true;
}
}
public int FindLessEqualIndex(int value)
{
int index = _items.BinarySearch(value);
return (index < 0) ? (-2 - index) : index;
}
public void RemoveRange(int index, int count)
{
if (count > 0)
{
_items.RemoveRange(index, count);
}
}
public int Last()
{
return _items[Count - 1];
}
public List<int> GetList()
{
return _items;
}
}
}
|