Change UniqueQueue to use a queue and a set.
This commit is contained in:
parent
227e4807b4
commit
bd0d786590
12
src/map.cpp
12
src/map.cpp
@ -1663,7 +1663,8 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks)
|
|||||||
/*
|
/*
|
||||||
Get a queued transforming liquid node
|
Get a queued transforming liquid node
|
||||||
*/
|
*/
|
||||||
v3s16 p0 = m_transforming_liquid.pop_front();
|
v3s16 p0 = m_transforming_liquid.front();
|
||||||
|
m_transforming_liquid.pop_front();
|
||||||
|
|
||||||
MapNode n0 = getNodeNoEx(p0);
|
MapNode n0 = getNodeNoEx(p0);
|
||||||
|
|
||||||
@ -1909,7 +1910,10 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks)
|
|||||||
}
|
}
|
||||||
//infostream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
|
//infostream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
|
||||||
while (must_reflow.size() > 0)
|
while (must_reflow.size() > 0)
|
||||||
m_transforming_liquid.push_back(must_reflow.pop_front());
|
{
|
||||||
|
m_transforming_liquid.push_back(must_reflow.front());
|
||||||
|
must_reflow.pop_front();
|
||||||
|
}
|
||||||
updateLighting(lighting_modified_blocks, modified_blocks);
|
updateLighting(lighting_modified_blocks, modified_blocks);
|
||||||
|
|
||||||
|
|
||||||
@ -2380,8 +2384,8 @@ void ServerMap::finishBlockMake(BlockMakeData *data,
|
|||||||
*/
|
*/
|
||||||
while(data->transforming_liquid.size() > 0)
|
while(data->transforming_liquid.size() > 0)
|
||||||
{
|
{
|
||||||
v3s16 p = data->transforming_liquid.pop_front();
|
m_transforming_liquid.push_back(data->transforming_liquid.front());
|
||||||
m_transforming_liquid.push_back(p);
|
data->transforming_liquid.pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -28,6 +28,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Queue with unique values with fast checking of value existence
|
Queue with unique values with fast checking of value existence
|
||||||
@ -44,36 +46,35 @@ public:
|
|||||||
true: value added
|
true: value added
|
||||||
false: value already exists
|
false: value already exists
|
||||||
*/
|
*/
|
||||||
bool push_back(Value value)
|
bool push_back(const Value& value)
|
||||||
{
|
{
|
||||||
// Check if already exists
|
if (m_set.insert(value).second)
|
||||||
if(m_map.find(value) != m_map.end())
|
{
|
||||||
return false;
|
m_queue.push(value);
|
||||||
|
|
||||||
// Add
|
|
||||||
m_map[value] = 0;
|
|
||||||
m_list.push_back(value);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
Value pop_front()
|
|
||||||
{
|
|
||||||
typename std::list<Value>::iterator i = m_list.begin();
|
|
||||||
Value value = *i;
|
|
||||||
m_map.erase(value);
|
|
||||||
m_list.erase(i);
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 size()
|
void pop_front()
|
||||||
{
|
{
|
||||||
return m_map.size();
|
m_set.erase(m_queue.front());
|
||||||
|
m_queue.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
const Value& front() const
|
||||||
|
{
|
||||||
|
return m_queue.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 size() const
|
||||||
|
{
|
||||||
|
return m_queue.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<Value, u8> m_map;
|
std::set<Value> m_set;
|
||||||
std::list<Value> m_list;
|
std::queue<Value> m_queue;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user