lixiaojun
2024-07-30 f45bba0b5ecf73df67af6cb60e57ea956d82a8ab
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Hydro.CommonBase
{
    [Serializable]
    public class DRange
    {
        
        public DRange(double min, double max)
        {
            Min = min;
            Max = max;
        }
        public DRange(DRange range)
        {
            if (range==null)
            {
                Min = 0;
                Max = 0;
            }
            else
            {
                Min = range.Min;
                Max = range.Max;
            }
            
        }
        public DRange()
        {
            Min = 0;
            Max = 0;
        }
        public double Min { get; set; }
        public double Max { get; set; }
 
        public double Length { get { return Max - Min; } }
 
        public bool IsInside(double x)
        {
            return x >= Min && x <= Max;
        }
        public bool isValid { get { return Min <= Max; } }
        public void Union(DRange range)
        {
            if (range.Min < Min)
            {
                Min = range.Min;
            }
            if (range.Max > Max)
            {
                Max = range.Max;
            }
        }   
        public static DRange Union(DRange range1, DRange range2)
        {
            DRange range = new DRange(range1);
            range.Union(range2);
            return range;
        }
        public override string ToString()
        {
            return $"{Min:0.000}-{Max:0.000}";
        }
    }
 
 
    public class IndexedDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        private List<TKey> keys = new List<TKey>();
 
        public TValue this[int index]
        {
            get { return this[keys[index]]; }
            set { this[keys[index]] = value; }
        }
 
        public new void Add(TKey key, TValue value)
        {
            base.Add(key, value);
            keys.Add(key);
        }
 
        public new bool Remove(TKey key)
        {
            if (base.Remove(key))
            {
                keys.Remove(key);
                return true;
            }
            return false;
        }
    }
    public class TStringList
    {
 
        private List<string> _list = new List<string>();
        private Dictionary<string, object> _objectDict = new Dictionary<string, object>();
        public int Count => _list.Count;
 
        public TStringList()
        {
 
        }
        public TStringList(IEnumerable<object> list)
        {
            foreach (var o in list)
            {
                string key = "";
                if (o != null)
                {
                    key = o.ToString();
                }
                string key0 = key;
                int i = 1;
                while (_objectDict.ContainsKey(key0))
                {
                    key0 = key + i++;
                }
                this._list.Add(key0);
                _objectDict.Add(key0, o);
            }
            // = list;
            //_list.ForEach(l => _objectDict.Add(l,null)); 
        }
        public Dictionary<string, object> ToDict()
        {
            return _objectDict;
        }
 
        
        // 添加元素和关联的对象
        public void Add(string s, object obj = null)
        {
            _list.Add(s);
            _objectDict[s] = obj;
        }
 
        public void Remove(int index)
        {
            _objectDict.Remove(_list[index]);
            _list.RemoveAt(index);
        }
 
        // 获取元素关联的对象
        public object Objects(int index) => _objectDict[_list[index]];
 
        // 设置文本,以换行符分隔的字符串
        public void SetText(string text)
        {
            _list.Clear();
            _objectDict.Clear();
 
            string[] lines = text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string line in lines)
            {
                _list.Add(line);
                _objectDict[line] = null;
            }
        }
        public void Free()
        {
            _list.Clear();
            _objectDict.Clear();
        }
        public void Clear()
        {
            Free();
        }
 
 
        public TStringList Values
        {
            get
            {
                List<object> list = new List<object>();
                foreach (string s in _list)
                {
                    list.Add(_objectDict[s]);
                }
                return new TStringList(list);
            }
        }
 
        public object this[int index]
        {
            get
            {
                //return _list[index].ToString();
                return _objectDict[_list[index]];
            }
            set
            {
                _objectDict[_list[index]] = value;
 
            }
        }
 
        // Assign 方法,将另一个 TStringList 的内容复制到当前列表
        public void Assign(TStringList sourceList)
        {
            Clear();
            foreach (string item in sourceList._list)
            {
                Add(item);
            }
        }
 
    }
 
    [Serializable]
    public class SaveDict: ConcurrentDictionary<ulong, double>
    {
        //ConcurrentDictionary<ulong, double> _dict;
        public SaveDict():base()
        {
            //_dict = new ConcurrentDictionary<ulong, double>();
        }
        public SaveDict(IEnumerable<KeyValuePair<ulong, double>> list):base(list)
        {
            //_dict = new ConcurrentDictionary<ulong, double>(list);
        }
 
 
 
    }
}