Replace various uses of std::set/map with btree containers.

pull/11/head
Jonathan G Rennison 7 years ago
parent 76de8f9b13
commit 9d5f34fea6

@ -32,12 +32,11 @@ static void ClearCargoMonitoring(CargoMonitorMap &cargo_monitor_map, CompanyID c
return;
}
CargoMonitorMap::iterator next;
for (CargoMonitorMap::iterator it = cargo_monitor_map.begin(); it != cargo_monitor_map.end(); it = next) {
next = it;
next++;
for (CargoMonitorMap::iterator it = cargo_monitor_map.begin(); it != cargo_monitor_map.end();) {
if (DecodeMonitorCompany(it->first) == company) {
cargo_monitor_map.erase(it);
it = cargo_monitor_map.erase(it);
} else {
++it;
}
}
}

@ -17,8 +17,7 @@
#include "industry.h"
#include "town.h"
#include "core/overflowsafe_type.hpp"
#include <map>
#include "3rdparty/cpp-btree/btree_map.h"
struct Station;
/**
@ -32,7 +31,7 @@ struct Station;
typedef uint32 CargoMonitorID; ///< Type of the cargo monitor number.
/** Map type for storing and updating active cargo monitor numbers and their amounts. */
typedef std::map<CargoMonitorID, OverflowSafeInt32> CargoMonitorMap;
typedef btree::btree_map<CargoMonitorID, OverflowSafeInt32> CargoMonitorMap;
extern CargoMonitorMap _cargo_pickups;
extern CargoMonitorMap _cargo_deliveries;

@ -33,8 +33,8 @@
#include "tunnelbridge_map.h"
#include "pathfinder/npf/aystar.h"
#include "saveload/saveload.h"
#include "3rdparty/cpp-btree/btree_set.h"
#include <deque>
#include <set>
#include "table/strings.h"
#include "table/sprites.h"
@ -1119,7 +1119,7 @@ static bool FlowRiver(TileIndex spring, TileIndex begin)
uint height = TileHeight(begin);
if (IsWaterTile(begin)) return DistanceManhattan(spring, begin) > _settings_game.game_creation.min_river_length;
std::set<TileIndex> marks;
btree::btree_set<TileIndex> marks;
SET_MARK(begin);
/* Breadth first search for the closest tile we can flow down to. */
@ -1156,7 +1156,7 @@ static bool FlowRiver(TileIndex spring, TileIndex begin)
/* Maybe we can make a lake. Find the Nth of the considered tiles. */
TileIndex lakeCenter = 0;
int i = RandomRange(count - 1) + 1;
std::set<TileIndex>::const_iterator cit = marks.begin();
btree::btree_set<TileIndex>::const_iterator cit = marks.begin();
while (--i) cit++;
lakeCenter = *cit;

@ -3,11 +3,12 @@
#include "../stdafx.h"
#include "../core/math_func.hpp"
#include "mcf.h"
#include "../3rdparty/cpp-btree/btree_map.h"
#include <set>
#include "../safeguards.h"
typedef std::map<NodeID, Path *> PathViaMap;
typedef btree::btree_map<NodeID, Path *> PathViaMap;
/**
* This is a wrapper around Tannotation* which also stores a cache of GetAnnotation() and GetNode()

@ -14,9 +14,9 @@
#include "../cargo_type.h"
#include "../vehicle_base.h"
#include "../3rdparty/cpp-btree/btree_set.h"
#include <vector>
#include <map>
#include <set>
/**
* Utility to refresh links a consist will visit.
@ -67,7 +67,7 @@ protected:
* Default constructor should not be called but has to be visible for
* usage in std::set.
*/
Hop() {NOT_REACHED();}
Hop() {}
/**
* Real constructor, only use this one.
@ -80,7 +80,7 @@ protected:
};
typedef std::vector<RefitDesc> RefitList;
typedef std::set<Hop> HopSet;
typedef btree::btree_set<Hop> HopSet;
Vehicle *vehicle; ///< Vehicle for which the links should be refreshed.
uint capacities[NUM_CARGO]; ///< Current added capacities per cargo ID in the consist.

@ -41,7 +41,6 @@
#include "date_func.h"
#include "string_func.h"
#include "network/network.h"
#include <map>
#include "smallmap_gui.h"
#include "genworld.h"
#include "error.h"
@ -52,6 +51,8 @@
#include "table/strings.h"
#include "table/build_industry.h"
#include "3rdparty/cpp-btree/btree_map.h"
#include "safeguards.h"
/* TTDPatch extended GRF format codec
@ -90,7 +91,7 @@ private:
};
/** Currently referenceable spritesets */
std::map<uint, SpriteSet> spritesets[GSF_END];
btree::btree_map<uint, SpriteSet> spritesets[GSF_END];
public:
/* Global state */
@ -347,6 +348,7 @@ struct GRFLocation {
uint32 grfid;
uint32 nfoline;
GRFLocation() { }
GRFLocation(uint32 grfid, uint32 nfoline) : grfid(grfid), nfoline(nfoline) { }
bool operator<(const GRFLocation &other) const
@ -360,8 +362,8 @@ struct GRFLocation {
}
};
static std::map<GRFLocation, SpriteID> _grm_sprites;
typedef std::map<GRFLocation, byte*> GRFLineToSpriteOverride;
static btree::btree_map<GRFLocation, SpriteID> _grm_sprites;
typedef btree::btree_map<GRFLocation, byte*> GRFLineToSpriteOverride;
static GRFLineToSpriteOverride _grf_line_to_action6_sprite_override;
/**
@ -5931,7 +5933,7 @@ static void CfgApply(ByteReader *buf)
GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
if (it != _grf_line_to_action6_sprite_override.end()) {
free(preload_sprite);
preload_sprite = _grf_line_to_action6_sprite_override[location];
preload_sprite = it->second;
} else {
_grf_line_to_action6_sprite_override[location] = preload_sprite;
}
@ -8760,7 +8762,7 @@ static void DecodeSpecialSprite(byte *buf, uint num, GrfLoadingStage stage)
FioReadBlock(buf, num);
} else {
/* Use the preloaded sprite data. */
buf = _grf_line_to_action6_sprite_override[location];
buf = it->second;
grfmsg(7, "DecodeSpecialSprite: Using preloaded pseudo sprite data");
/* Skip the real (original) content of this action. */

@ -24,6 +24,8 @@
#include "table/strings.h"
#include "table/palette_convert.h"
#include "3rdparty/cpp-btree/btree_map.h"
#include "safeguards.h"
/* Default of 4MB spritecache */
@ -476,7 +478,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
/** Map from sprite numbers to position in the GRF file. */
static std::map<uint32, size_t> _grf_sprite_offsets;
static btree::btree_map<uint32, size_t> _grf_sprite_offsets;
/**
* Get the file offset for a specific sprite in the sprite section of a GRF.
@ -485,7 +487,8 @@ static std::map<uint32, size_t> _grf_sprite_offsets;
*/
size_t GetGRFSpriteOffset(uint32 id)
{
return _grf_sprite_offsets.find(id) != _grf_sprite_offsets.end() ? _grf_sprite_offsets[id] : SIZE_MAX;
auto iter = _grf_sprite_offsets.find(id);
return iter != _grf_sprite_offsets.end() ? iter->second : SIZE_MAX;
}
/**

@ -21,15 +21,15 @@
#include "table/strings.h"
#include <map>
#include <set>
#include "3rdparty/cpp-btree/btree_set.h"
#include "3rdparty/cpp-btree/btree_map.h"
#include "safeguards.h"
/** Set of tiles. */
typedef std::set<TileIndex> TileIndexSet;
typedef btree::btree_set<TileIndex> TileIndexSet;
/** Mapping of tiles to their height. */
typedef std::map<TileIndex, int> TileIndexToHeightMap;
typedef btree::btree_map<TileIndex, int> TileIndexToHeightMap;
/** State of the terraforming. */
struct TerraformerState {

@ -18,7 +18,7 @@
#include "rail_map.h"
#include "tile_type.h"
#include "group_type.h"
#include <map>
#include "3rdparty/cpp-btree/btree_map.h"
#include <vector>
struct Train;
@ -50,7 +50,7 @@ struct TraceRestrictMappingItem {
: program_id(program_id_) { }
};
typedef std::map<TraceRestrictRefId, TraceRestrictMappingItem> TraceRestrictMapping;
typedef btree::btree_map<TraceRestrictRefId, TraceRestrictMappingItem> TraceRestrictMapping;
/** The actual mapping from TraceRestrictRefId to TraceRestrictProgramID. */
extern TraceRestrictMapping _tracerestrictprogram_mapping;

@ -57,6 +57,7 @@
#include "tbtr_template_vehicle_func.h"
#include "string_func.h"
#include "scope_info.h"
#include "3rdparty/cpp-btree/btree_set.h"
#include "table/strings.h"
@ -75,7 +76,7 @@ uint16 _returned_mail_refit_capacity; ///< Stores the mail capacity after a refi
VehiclePool _vehicle_pool("Vehicle");
INSTANTIATE_POOL_METHODS(Vehicle)
static std::set<Vehicle *> _vehicles_to_pay_repair;
static btree::btree_set<Vehicle *> _vehicles_to_pay_repair;
/**
* Determine shared bounds of all sprites.

Loading…
Cancel
Save