-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestCollections.cs
137 lines (121 loc) · 5.64 KB
/
TestCollections.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
namespace lab1
{
class TestCollections
{
private System.Collections.Generic.List<Person> _listOfPersons = new List<Person>();
private System.Collections.Generic.List<string> _listOfStrings= new List<string>();
private System.Collections.Generic.Dictionary<Person, Student> _dictionaryPersonStudent = new Dictionary<Person, Student>();
private System.Collections.Generic.Dictionary<string, Student> _dictionarStringStudent = new Dictionary<string, Student>();
public List<Person> ListOfPersons
{
get
{
return _listOfPersons;
}
set
{
_listOfPersons = value;
}
}
public List<string> ListOfStrings {
get {
return _listOfStrings;
}
set
{
_listOfStrings = value;
}
}
public Dictionary<Person, Student> DictionaryPersonStudent
{
get
{
return _dictionaryPersonStudent;
}
set {
_dictionaryPersonStudent = value;
}
}
public Dictionary<string, Student> DictionarStringStudent
{
get
{
return _dictionarStringStudent;
}
set
{
_dictionarStringStudent = value;
}
}
public TestCollections(int value) //конструктор
{
for (int i = 0; i < value; i++)
{
_listOfPersons.Add(new Person("Имя" + i.ToString(), "Фамилия" + i.ToString(), new DateTime(2000, 1, 1)));
_dictionaryPersonStudent.Add(new Person("Имя" + i.ToString(), "Фамилия" + i.ToString(), new DateTime(2000, 1, 1)), GenerateStudent(i));
_listOfStrings.Add(i.ToString());
_dictionarStringStudent.Add(i.ToString(), GenerateStudent(i));
}
}
public static Student GenerateStudent(int value) //генерация студента
{
Student newStudent = new Student("Имя" + value.ToString(), "Фамилия" + value.ToString(), new DateTime(2000, 1, 1), 11, Education.Specialist);
return newStudent;
}
//public T KeyByValue<T, W>(this Dictionary<T, W> dict, W val) //функция для поиска ключа по значению
//{
//T key = default;
//foreach (KeyValuePair<T, W> pair in dict)
//{
//if (EqualityComparer<W>.Default.Equals(pair.Value, val))
//{
//key = pair.Key;
//break;
//}
//}
//return key;
//}
public void TimeSearch(string str1, Person person, Student student)
{
Student value;
DateTime start_time = DateTime.Now;
//int start_time = Environment.TickCount; //поиск по списку персон
ListOfPersons.BinarySearch(person);
//var person2 = ListOfPersons.First(o => o.Equals(person));
//int end_time= Environment.TickCount;
DateTime end_time = DateTime.Now;
Console.WriteLine("Время поиска по списку персон: "+(end_time - start_time).ToString());
start_time = DateTime.Now; //поиск по списку стрингов
ListOfStrings.BinarySearch(str1);
end_time = DateTime.Now;
Console.WriteLine("Вемя поиска по списку строк: " + (end_time - start_time).ToString());
start_time = DateTime.Now; //поиск в словаре персона-студент по ключу
if (_dictionaryPersonStudent.TryGetValue(person, out value))
{
Student stud = value;
//Console.WriteLine(stud);
}
end_time = DateTime.Now;
Console.WriteLine("Время поиска в словаре персона-студент по ключу: " + (end_time - start_time).ToString());
//start_time = Environment.TickCount; //поиск в словаре персона-студент по значению
//Person pers = _dictionaryPersonStudent.Where(x=>x.Value == student).FirstOrDefault().Key;
//end_time = Environment.TickCount;
//Console.WriteLine("Время поиска в словаре персона-студент по значению: " + (end_time - start_time).ToString());
start_time = DateTime.Now; //поиск в словаре строка-студент по ключу
if (_dictionarStringStudent.TryGetValue(str1, out value))
{
Student stud = value;
//Console.WriteLine(stud);
}
end_time = DateTime.Now;
Console.WriteLine("Время поиска в словаре строка-студент по ключу: " + (end_time - start_time).ToString());
//start_time = Environment.TickCount; //поиск в словаре строка-студент по значению
//string str2 = _dictionarStringStudent.Where(x => x.Value == student).FirstOrDefault().Key;
//end_time = Environment.TickCount;
//Console.WriteLine("Время поиска в словаре строка-студент по значению: " + (end_time - start_time).ToString());
}
}
}