src/ai/api/ai_abstractlist.cpp
branchnoai
changeset 9664 c5741021bf59
parent 9606 91086d7330a5
child 9665 e889ac1e663a
equal deleted inserted replaced
9663:f854f05bbbce 9664:c5741021bf59
   236 void AIAbstractList::RemoveItem(int32 item)
   236 void AIAbstractList::RemoveItem(int32 item)
   237 {
   237 {
   238 	if (!this->HasItem(item)) return;
   238 	if (!this->HasItem(item)) return;
   239 
   239 
   240 	this->buckets[this->GetValue(item)].erase(item);
   240 	this->buckets[this->GetValue(item)].erase(item);
       
   241 	if (this->buckets[this->GetValue(item)].empty()) this->buckets.erase(this->GetValue(item));
   241 	this->items.erase(item);
   242 	this->items.erase(item);
   242 }
   243 }
   243 
   244 
   244 int32 AIAbstractList::Begin()
   245 int32 AIAbstractList::Begin()
   245 {
   246 {
   269 int32 AIAbstractList::GetValue(int32 item)
   270 int32 AIAbstractList::GetValue(int32 item)
   270 {
   271 {
   271 	if (!this->HasItem(item)) return 0;
   272 	if (!this->HasItem(item)) return 0;
   272 
   273 
   273 	return this->items[item];
   274 	return this->items[item];
       
   275 }
       
   276 
       
   277 bool AIAbstractList::SetValue(int32 item, int32 value)
       
   278 {
       
   279 	if (!this->HasItem(item)) return false;
       
   280 
       
   281 	this->buckets[this->GetValue(item)].erase(item);
       
   282 	if (this->buckets[this->GetValue(item)].empty()) this->buckets.erase(this->GetValue(item));
       
   283 	this->items[item] = value;
       
   284 	this->buckets[value].insert(item);
       
   285 
       
   286 	return true;
   274 }
   287 }
   275 
   288 
   276 void AIAbstractList::SortByItem(bool ascending)
   289 void AIAbstractList::SortByItem(bool ascending)
   277 {
   290 {
   278 	delete this->sorter;
   291 	delete this->sorter;