author | truebrain |
Fri, 22 Feb 2008 12:30:17 +0000 | |
branch | noai |
changeset 9737 | ee408edf3851 |
parent 9731 | 9b1552d0fd9b |
child 9752 | bd87e54186f2 |
permissions | -rw-r--r-- |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
1 |
/* $Id$ */ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
2 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
3 |
/** @file ai_abstractlist.cpp Implementation of AIAbstractList */ |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
4 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
5 |
#include "ai_abstractlist.hpp" |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
6 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
7 |
/** |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
8 |
* Base class for any AIAbstractList sorter. |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
9 |
*/ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
10 |
class AIAbstractListSorter { |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
11 |
protected: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
12 |
AIAbstractList *list; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
13 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
14 |
public: |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
15 |
/** |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
16 |
* Virtual dtor, needed to mute warnings. |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
17 |
*/ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
18 |
virtual ~AIAbstractListSorter() { } |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
19 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
20 |
/** |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
21 |
* Get the first item of the sorter. |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
22 |
*/ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
23 |
virtual int32 Begin() = 0; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
24 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
25 |
/** |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
26 |
* Get the next item of the sorter. |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
27 |
*/ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
28 |
virtual int32 Next() = 0; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
29 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
30 |
/** |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
31 |
* See if there is a next item of the sorter. |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
32 |
*/ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
33 |
virtual bool HasNext() = 0; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
34 |
}; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
35 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
36 |
/** |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
37 |
* Sort by value, ascending. |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
38 |
*/ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
39 |
class AIAbstractListSorterValueAscending : public AIAbstractListSorter { |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
40 |
private: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
41 |
AIAbstractList::AIAbstractListBucket::iterator bucket_iter; |
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
42 |
AIAbstractList::AIItemList *bucket_list; |
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
43 |
AIAbstractList::AIItemList::iterator bucket_list_iter; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
44 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
45 |
public: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
46 |
AIAbstractListSorterValueAscending(AIAbstractList *list) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
47 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
48 |
this->list = list; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
49 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
50 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
51 |
int32 Begin() |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
52 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
53 |
if (this->list->buckets.empty()) return 0; |
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
54 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
55 |
this->bucket_iter = this->list->buckets.begin(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
56 |
this->bucket_list = &(*this->bucket_iter).second; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
57 |
this->bucket_list_iter = this->bucket_list->begin(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
58 |
return *bucket_list_iter; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
59 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
60 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
61 |
int32 Next() |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
62 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
63 |
if (this->list->buckets.empty()) return 0; |
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
64 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
65 |
this->bucket_list_iter++; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
66 |
if (this->bucket_list_iter == this->bucket_list->end()) { |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
67 |
this->bucket_iter++; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
68 |
if (this->bucket_iter == this->list->buckets.end()) return 0; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
69 |
this->bucket_list = &(*this->bucket_iter).second; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
70 |
this->bucket_list_iter = this->bucket_list->begin(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
71 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
72 |
return *bucket_list_iter; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
73 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
74 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
75 |
bool HasNext() |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
76 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
77 |
if (this->list->buckets.empty()) return false; |
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
78 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
79 |
return this->bucket_iter != this->list->buckets.end() && this->bucket_list_iter != this->bucket_list->end(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
80 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
81 |
}; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
82 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
83 |
/** |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
84 |
* Sort by value, descending. |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
85 |
*/ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
86 |
class AIAbstractListSorterValueDescending : public AIAbstractListSorter { |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
87 |
private: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
88 |
AIAbstractList::AIAbstractListBucket::reverse_iterator bucket_iter; |
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
89 |
AIAbstractList::AIItemList *bucket_list; |
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
90 |
AIAbstractList::AIItemList::reverse_iterator bucket_list_iter; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
91 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
92 |
public: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
93 |
AIAbstractListSorterValueDescending(AIAbstractList *list) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
94 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
95 |
this->list = list; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
96 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
97 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
98 |
int32 Begin() |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
99 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
100 |
if (this->list->buckets.empty()) return 0; |
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
101 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
102 |
this->bucket_iter = this->list->buckets.rbegin(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
103 |
this->bucket_list = &(*this->bucket_iter).second; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
104 |
this->bucket_list_iter = this->bucket_list->rbegin(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
105 |
return *bucket_list_iter; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
106 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
107 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
108 |
int32 Next() |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
109 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
110 |
if (this->list->buckets.empty()) return 0; |
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
111 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
112 |
this->bucket_list_iter++; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
113 |
if (this->bucket_list_iter == this->bucket_list->rend()) { |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
114 |
this->bucket_iter++; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
115 |
if (this->bucket_iter == this->list->buckets.rend()) return 0; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
116 |
this->bucket_list = &(*this->bucket_iter).second; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
117 |
this->bucket_list_iter = this->bucket_list->rbegin(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
118 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
119 |
return *bucket_list_iter; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
120 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
121 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
122 |
bool HasNext() |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
123 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
124 |
if (this->list->buckets.empty()) return false; |
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
125 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
126 |
return this->bucket_iter != this->list->buckets.rend() && this->bucket_list_iter != this->bucket_list->rend(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
127 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
128 |
}; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
129 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
130 |
/** |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
131 |
* Sort by item, ascending. |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
132 |
*/ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
133 |
class AIAbstractListSorterItemAscending : public AIAbstractListSorter { |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
134 |
private: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
135 |
AIAbstractList::AIAbstractListMap::iterator item_iter; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
136 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
137 |
public: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
138 |
AIAbstractListSorterItemAscending(AIAbstractList *list) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
139 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
140 |
this->list = list; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
141 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
142 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
143 |
int32 Begin() |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
144 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
145 |
if (this->list->items.empty()) return 0; |
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
146 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
147 |
this->item_iter = this->list->items.begin(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
148 |
return (*this->item_iter).first; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
149 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
150 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
151 |
int32 Next() |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
152 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
153 |
if (this->list->items.empty()) return 0; |
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
154 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
155 |
this->item_iter++; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
156 |
return (*this->item_iter).first; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
157 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
158 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
159 |
bool HasNext() |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
160 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
161 |
if (this->list->items.empty()) return false; |
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
162 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
163 |
return this->item_iter != this->list->items.end(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
164 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
165 |
}; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
166 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
167 |
/** |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
168 |
* Sort by item, descending. |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
169 |
*/ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
170 |
class AIAbstractListSorterItemDescending : public AIAbstractListSorter { |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
171 |
private: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
172 |
AIAbstractList::AIAbstractListMap::reverse_iterator item_iter; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
173 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
174 |
public: |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
175 |
AIAbstractListSorterItemDescending(AIAbstractList *list) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
176 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
177 |
this->list = list; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
178 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
179 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
180 |
int32 Begin() |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
181 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
182 |
if (this->list->items.empty()) return 0; |
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
183 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
184 |
this->item_iter = this->list->items.rbegin(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
185 |
return (*this->item_iter).first; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
186 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
187 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
188 |
int32 Next() |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
189 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
190 |
if (this->list->items.empty()) return 0; |
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
191 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
192 |
this->item_iter++; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
193 |
return (*this->item_iter).first; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
194 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
195 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
196 |
bool HasNext() |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
197 |
{ |
9606
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
198 |
if (this->list->items.empty()) return false; |
91086d7330a5
(svn r9750) [NoAI] -Fix: if AIAbstractList is empty, don't make the sorters segfault
truelight
parents:
9593
diff
changeset
|
199 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
200 |
return this->item_iter != this->list->items.rend(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
201 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
202 |
}; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
203 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
204 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
205 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
206 |
AIAbstractList::AIAbstractList() |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
207 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
208 |
/* Default sorter */ |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
209 |
this->sorter = new AIAbstractListSorterValueDescending(this); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
210 |
this->sorter_type = SORT_BY_VALUE; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
211 |
this->sort_ascending = false; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
212 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
213 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
214 |
AIAbstractList::~AIAbstractList() |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
215 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
216 |
delete this->sorter; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
217 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
218 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
219 |
bool AIAbstractList::HasItem(int32 item) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
220 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
221 |
return this->items.count(item) == 1; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
222 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
223 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
224 |
void AIAbstractList::Clear() |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
225 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
226 |
this->items.clear(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
227 |
this->buckets.clear(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
228 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
229 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
230 |
void AIAbstractList::AddItem(int32 item) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
231 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
232 |
if (this->HasItem(item)) return; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
233 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
234 |
this->items[item] = 0; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
235 |
this->buckets[0].insert(item); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
236 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
237 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
238 |
void AIAbstractList::RemoveItem(int32 item) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
239 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
240 |
if (!this->HasItem(item)) return; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
241 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
242 |
this->buckets[this->GetValue(item)].erase(item); |
9664
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
243 |
if (this->buckets[this->GetValue(item)].empty()) this->buckets.erase(this->GetValue(item)); |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
244 |
this->items.erase(item); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
245 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
246 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
247 |
int32 AIAbstractList::Begin() |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
248 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
249 |
return this->sorter->Begin(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
250 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
251 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
252 |
int32 AIAbstractList::Next() |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
253 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
254 |
return this->sorter->Next(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
255 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
256 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
257 |
bool AIAbstractList::IsEmpty() |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
258 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
259 |
return this->items.empty(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
260 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
261 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
262 |
bool AIAbstractList::HasNext() |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
263 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
264 |
return this->sorter->HasNext(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
265 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
266 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
267 |
int32 AIAbstractList::Count() |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
268 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
269 |
return this->items.size(); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
270 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
271 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
272 |
int32 AIAbstractList::GetValue(int32 item) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
273 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
274 |
if (!this->HasItem(item)) return 0; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
275 |
|
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
276 |
return this->items[item]; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
277 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
278 |
|
9664
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
279 |
bool AIAbstractList::SetValue(int32 item, int32 value) |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
280 |
{ |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
281 |
if (!this->HasItem(item)) return false; |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
282 |
|
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
283 |
this->buckets[this->GetValue(item)].erase(item); |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
284 |
if (this->buckets[this->GetValue(item)].empty()) this->buckets.erase(this->GetValue(item)); |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
285 |
this->items[item] = value; |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
286 |
this->buckets[value].insert(item); |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
287 |
|
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
288 |
return true; |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
289 |
} |
c5741021bf59
(svn r10577) [NoAI] -Add: added ChangeItem to AIList
truelight
parents:
9606
diff
changeset
|
290 |
|
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
291 |
void AIAbstractList::Sort(SorterType sorter, bool ascending) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
292 |
{ |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
293 |
if (sorter == this->sorter_type && ascending == this->sort_ascending) return; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
294 |
|
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
295 |
delete this->sorter; |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
296 |
switch (sorter) { |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
297 |
case SORT_BY_ITEM: |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
298 |
if (ascending) this->sorter = new AIAbstractListSorterItemAscending(this); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
299 |
else this->sorter = new AIAbstractListSorterItemDescending(this); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
300 |
break; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
301 |
|
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
302 |
case SORT_BY_VALUE: |
9702
e782b59f1f6a
(svn r11075) [NoAI] -Fix: sorting on value did not work as expected. Patch by GeekToo.
rubidium
parents:
9665
diff
changeset
|
303 |
if (ascending) this->sorter = new AIAbstractListSorterValueAscending(this); |
e782b59f1f6a
(svn r11075) [NoAI] -Fix: sorting on value did not work as expected. Patch by GeekToo.
rubidium
parents:
9665
diff
changeset
|
304 |
else this->sorter = new AIAbstractListSorterValueDescending(this); |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
305 |
break; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
306 |
|
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
307 |
default: |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
308 |
this->Sort(SORT_BY_ITEM, false); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
309 |
return; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
310 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
311 |
this->sorter_type = sorter; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
312 |
this->sort_ascending = ascending; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
313 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
314 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
315 |
void AIAbstractList::RemoveAboveValue(int32 value) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
316 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
317 |
for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
318 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
319 |
if ((*iter).second > value) this->items.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
320 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
321 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
322 |
for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
323 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
324 |
if ((*iter).first > value) this->buckets.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
325 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
326 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
327 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
328 |
void AIAbstractList::RemoveBelowValue(int32 value) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
329 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
330 |
for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
331 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
332 |
if ((*iter).second < value) this->items.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
333 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
334 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
335 |
for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
336 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
337 |
if ((*iter).first < value) this->buckets.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
338 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
339 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
340 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
341 |
void AIAbstractList::RemoveBetweenValue(int32 start, int32 end) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
342 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
343 |
for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
344 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
345 |
if ((*iter).second > start && (*iter).second < end) this->items.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
346 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
347 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
348 |
for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
349 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
350 |
if ((*iter).first > start && (*iter).first < end) this->buckets.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
351 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
352 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
353 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
354 |
void AIAbstractList::RemoveValue(int32 value) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
355 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
356 |
for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
357 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
358 |
if ((*iter).second == value) this->items.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
359 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
360 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
361 |
for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
362 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
363 |
if ((*iter).first == value) this->buckets.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
364 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
365 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
366 |
|
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
367 |
void AIAbstractList::RemoveTop(int32 count) |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
368 |
{ |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
369 |
if (!this->sort_ascending) { |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
370 |
this->Sort(this->sorter_type, !this->sort_ascending); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
371 |
this->RemoveBottom(count); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
372 |
this->Sort(this->sorter_type, !this->sort_ascending); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
373 |
return; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
374 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
375 |
|
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
376 |
switch (this->sorter_type) { |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
377 |
default: NOT_REACHED(); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
378 |
case SORT_BY_VALUE: |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
379 |
for (AIAbstractListBucket::iterator iter = this->buckets.begin(); iter != this->buckets.end(); iter = this->buckets.begin()) { |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
380 |
AIItemList *items = &(*iter).second; |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
381 |
size_t size = items->size(); |
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
382 |
for (AIItemList::iterator iter = items->begin(); iter != items->end(); iter = items->begin()) { |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
383 |
if (--count < 0) return; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
384 |
this->RemoveItem(*iter); |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
385 |
/* When the last item is removed from the bucket, the bucket itself is removed. |
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
386 |
* This means that the iterators can be invalid after a call to RemoveItem. |
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
387 |
*/ |
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
388 |
if (--size == 0) break; |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
389 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
390 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
391 |
break; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
392 |
|
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
393 |
case SORT_BY_ITEM: |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
394 |
for (AIAbstractListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter = this->items.begin()) { |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
395 |
if (--count < 0) return; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
396 |
this->RemoveItem((*iter).first); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
397 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
398 |
break; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
399 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
400 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
401 |
|
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
402 |
void AIAbstractList::RemoveBottom(int32 count) |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
403 |
{ |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
404 |
if (!this->sort_ascending) { |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
405 |
this->Sort(this->sorter_type, !this->sort_ascending); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
406 |
this->RemoveTop(count); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
407 |
this->Sort(this->sorter_type, !this->sort_ascending); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
408 |
return; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
409 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
410 |
|
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
411 |
switch (this->sorter_type) { |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
412 |
default: NOT_REACHED(); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
413 |
case SORT_BY_VALUE: |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
414 |
for (AIAbstractListBucket::reverse_iterator iter = this->buckets.rbegin(); iter != this->buckets.rend(); iter = this->buckets.rbegin()) { |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
415 |
AIItemList *items = &(*iter).second; |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
416 |
size_t size = items->size(); |
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
417 |
for (AIItemList::reverse_iterator iter = items->rbegin(); iter != items->rend(); iter = items->rbegin()) { |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
418 |
if (--count < 0) return; |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
419 |
this->RemoveItem(*iter); |
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
420 |
/* When the last item is removed from the bucket, the bucket itself is removed. |
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
421 |
* This means that the iterators can be invalid after a call to RemoveItem. |
9721
9a27928bcd5e
(svn r11497) [NoAI] -Fix: when removing the last item from a bucket, the bucket gets removed invalidating iterators. Based on a patch by xargonax.
rubidium
parents:
9702
diff
changeset
|
422 |
*/ |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
423 |
if (--size == 0) break; |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
424 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
425 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
426 |
|
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
427 |
case SORT_BY_ITEM: |
9731
9b1552d0fd9b
(svn r12210) [NoAI] -Fix: iterators can become invalid after a call to RemoveItem()
glx
parents:
9721
diff
changeset
|
428 |
for (AIAbstractListMap::reverse_iterator iter = this->items.rbegin(); iter != this->items.rend(); iter = this->items.rbegin()) { |
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
429 |
if (--count < 0) return; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
430 |
this->RemoveItem((*iter).first); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
431 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
432 |
break; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
433 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
434 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
435 |
|
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
436 |
void AIAbstractList::RemoveList(AIAbstractList *list) |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
437 |
{ |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
438 |
AIAbstractListMap *list_items = &list->items; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
439 |
for (AIAbstractListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) { |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
440 |
this->RemoveItem((*iter).first); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
441 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
442 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
443 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
444 |
void AIAbstractList::KeepAboveValue(int32 value) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
445 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
446 |
for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
447 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
448 |
if ((*iter).second <= value) this->items.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
449 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
450 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
451 |
for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
452 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
453 |
if ((*iter).first <= value) this->buckets.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
454 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
455 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
456 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
457 |
void AIAbstractList::KeepBelowValue(int32 value) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
458 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
459 |
for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
460 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
461 |
if ((*iter).second >= value) this->items.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
462 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
463 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
464 |
for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
465 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
466 |
if ((*iter).first >= value) this->buckets.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
467 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
468 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
469 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
470 |
void AIAbstractList::KeepBetweenValue(int32 start, int32 end) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
471 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
472 |
for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
473 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
474 |
if ((*iter).second <= start || (*iter).second >= end) this->items.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
475 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
476 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
477 |
for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
478 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
479 |
if ((*iter).first <= start || (*iter).first >= end) this->buckets.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
480 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
481 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
482 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
483 |
void AIAbstractList::KeepValue(int32 value) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
484 |
{ |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
485 |
for (AIAbstractListMap::iterator next_iter, iter = this->items.begin(); iter != this->items.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
486 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
487 |
if ((*iter).second != value) this->items.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
488 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
489 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
490 |
for (AIAbstractListBucket::iterator next_iter, iter = this->buckets.begin(); iter != this->buckets.end(); iter = next_iter) { |
9581
398688c1a07a
(svn r9605) [NoAI] -Fix: RemoveXXXValue and KeepXXXValue could cause infinite loops
truelight
parents:
9580
diff
changeset
|
491 |
next_iter = iter; next_iter++; |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
492 |
if ((*iter).first != value) this->buckets.erase(iter); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
493 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
494 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
495 |
|
9665
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
496 |
void AIAbstractList::KeepTop(int32 count) |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
497 |
{ |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
498 |
this->RemoveBottom(this->Count() - count); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
499 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
500 |
|
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
501 |
void AIAbstractList::KeepBottom(int32 count) |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
502 |
{ |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
503 |
this->RemoveTop(this->Count() - count); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
504 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
505 |
|
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
506 |
void AIAbstractList::KeepList(AIAbstractList *list) |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
507 |
{ |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
508 |
AIAbstractList tmp; |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
509 |
for (AIAbstractListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) { |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
510 |
tmp.AddItem((*iter).first); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
511 |
tmp.SetValue((*iter).first, (*iter).second); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
512 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
513 |
|
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
514 |
tmp.RemoveList(list); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
515 |
this->RemoveList(&tmp); |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
516 |
} |
e889ac1e663a
(svn r10579) [NoAI] -Add: functions to remove/keep the top/bottom X items from a list.
rubidium
parents:
9664
diff
changeset
|
517 |
|
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
518 |
void AIAbstractList::Valuate(const AIAbstractList::Valuator &proc) |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
519 |
{ |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
520 |
this->buckets.clear(); |
9593
012f29f59906
(svn r9626) [NoAI] -Change: renamed AIList to AIAbstractList and hide 'AddItem' and 'RemoveItem'
truelight
parents:
9589
diff
changeset
|
521 |
for (AIAbstractListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) { |
9589
2fbda08db406
(svn r9622) [NoAI] -Add: added AITownList, which lists all towns (and which you can iterate)
truelight
parents:
9581
diff
changeset
|
522 |
int32 value = proc.Valuate((*iter).first); |
9579
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
523 |
(*iter).second = value; |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
524 |
this->buckets[value].insert((*iter).first); |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
525 |
} |
632263c0cf5a
(svn r9603) [NoAI] -Add: added AIList(), a simple list in which you can add item/value pairs. You can sort them, walk them, and valuate them
truelight
parents:
diff
changeset
|
526 |
} |