Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove map/set when not strictly needed #1039

Merged
merged 6 commits into from
Aug 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/yocto/yocto_bvh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "yocto_bvh.h"

#include <algorithm>
#include <atomic>
#include <cstring>
#include <deque>
Expand Down
58 changes: 0 additions & 58 deletions libs/yocto/yocto_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

#include <cmath>
#include <cstdint>
#include <functional>
#include <limits>
#include <utility>

Expand Down Expand Up @@ -654,21 +653,6 @@ inline void swap(vec4i& a, vec4i& b);

} // namespace yocto

// -----------------------------------------------------------------------------
// VECTOR HASHING
// -----------------------------------------------------------------------------
namespace std {

// Hash functor for vector for use with hash_map
template <>
struct hash<yocto::vec2i>;
template <>
struct hash<yocto::vec3i>;
template <>
struct hash<yocto::vec4i>;

} // namespace std

// -----------------------------------------------------------------------------
// MATRICES
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -1942,48 +1926,6 @@ inline void swap(vec4i& a, vec4i& b) { std::swap(a, b); }

} // namespace yocto

// -----------------------------------------------------------------------------
// IMPLEMENRTATION OF VECTOR HASHING
// -----------------------------------------------------------------------------
namespace std {

// Hash functor for vector for use with hash_map
template <>
struct hash<yocto::vec2i> {
size_t operator()(const yocto::vec2i& v) const {
static const auto hasher = std::hash<int>();
auto h = (size_t)0;
h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2);
return h;
}
};
template <>
struct hash<yocto::vec3i> {
size_t operator()(const yocto::vec3i& v) const {
static const auto hasher = std::hash<int>();
auto h = (size_t)0;
h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.z) + 0x9e3779b9 + (h << 6) + (h >> 2);
return h;
}
};
template <>
struct hash<yocto::vec4i> {
size_t operator()(const yocto::vec4i& v) const {
static const auto hasher = std::hash<int>();
auto h = (size_t)0;
h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.z) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.w) + 0x9e3779b9 + (h << 6) + (h >> 2);
return h;
}
};

} // namespace std

// -----------------------------------------------------------------------------
// MATRICES
// -----------------------------------------------------------------------------
Expand Down
19 changes: 19 additions & 0 deletions libs/yocto/yocto_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ using namespace std::string_literals;

} // namespace yocto

// -----------------------------------------------------------------------------
// VECTOR HASHING
// -----------------------------------------------------------------------------
namespace std {

// Hash functor for vector for use with hash_map
template <>
struct hash<yocto::vec2i> {
size_t operator()(const yocto::vec2i& v) const {
static const auto hasher = std::hash<int>();
auto h = (size_t)0;
h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2);
return h;
}
};

} // namespace std

// -----------------------------------------------------------------------------
// UTILITIES
// -----------------------------------------------------------------------------
Expand Down
5 changes: 0 additions & 5 deletions libs/yocto/yocto_modelio.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <array>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include "yocto_math.h"
Expand All @@ -54,7 +53,6 @@ namespace yocto {
// using directives
using std::array;
using std::string;
using std::unordered_map;
using std::vector;

} // namespace yocto
Expand Down Expand Up @@ -223,9 +221,6 @@ struct obj_texture {
bool clamp = false; // clamp to edge
float scale = 1; // scale for bump/displacement

// Properties not explicitly handled.
unordered_map<string, vector<float>> props;

obj_texture() {}
explicit obj_texture(const char* path) : path{path} {}
explicit obj_texture(const string& path) : path{path} {}
Expand Down
11 changes: 7 additions & 4 deletions libs/yocto/yocto_shading.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
// -----------------------------------------------------------------------------

#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#include "yocto_math.h"
#include "yocto_sampling.h"
Expand All @@ -51,7 +51,7 @@ namespace yocto {
// using directives
using std::pair;
using std::string;
using std::unordered_map;
using std::vector;

} // namespace yocto

Expand Down Expand Up @@ -855,7 +855,7 @@ inline float sample_phasefunction_pdf(

// Conductor etas
inline pair<vec3f, vec3f> conductor_eta(const string& name) {
static const unordered_map<string, pair<vec3f, vec3f>> metal_ior_table = {
static const vector<pair<string, pair<vec3f, vec3f>>> metal_ior_table = {
{"a-C", {{2.9440999183f, 2.2271502925f, 1.9681668794f},
{0.8874329109f, 0.7993216383f, 0.8152862927f}}},
{"Ag", {{0.1552646489f, 0.1167232965f, 0.1383806959f},
Expand Down Expand Up @@ -937,7 +937,10 @@ inline pair<vec3f, vec3f> conductor_eta(const string& name) {
{"W", {{4.3707029924f, 3.3002972445f, 2.9982666528f},
{3.5006778591f, 2.6048652781f, 2.2731930614f}}},
};
return metal_ior_table.at(name);
for (auto& [ename, etas] : metal_ior_table) {
if (ename == name) return etas;
}
return {zero3f, zero3f};
}

} // namespace yocto
Expand Down
42 changes: 42 additions & 0 deletions libs/yocto/yocto_shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,48 @@ vector<vec3f> align_vertices(

} // namespace yocto

// -----------------------------------------------------------------------------
// VECTOR HASHING
// -----------------------------------------------------------------------------
namespace std {

// Hash functor for vector for use with hash_map
template <>
struct hash<yocto::vec2i> {
size_t operator()(const yocto::vec2i& v) const {
static const auto hasher = std::hash<int>();
auto h = (size_t)0;
h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2);
return h;
}
};
template <>
struct hash<yocto::vec3i> {
size_t operator()(const yocto::vec3i& v) const {
static const auto hasher = std::hash<int>();
auto h = (size_t)0;
h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.z) + 0x9e3779b9 + (h << 6) + (h >> 2);
return h;
}
};
template <>
struct hash<yocto::vec4i> {
size_t operator()(const yocto::vec4i& v) const {
static const auto hasher = std::hash<int>();
auto h = (size_t)0;
h ^= hasher(v.x) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.y) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.z) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= hasher(v.w) + 0x9e3779b9 + (h << 6) + (h >> 2);
return h;
}
};

} // namespace std

// -----------------------------------------------------------------------------
// EDGES AND ADJACENCIES
// -----------------------------------------------------------------------------
Expand Down
5 changes: 0 additions & 5 deletions libs/yocto_gui/yocto_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@

#include <yocto/yocto_commonio.h>

#include <unordered_map>
#include <unordered_set>

#include "ext/glad/glad.h"

#ifdef _WIN32
Expand All @@ -47,8 +44,6 @@
namespace yocto {

// using directives
using std::unordered_map;
using std::unordered_set;
using namespace std::string_literals;

} // namespace yocto
Expand Down
2 changes: 0 additions & 2 deletions libs/yocto_gui/yocto_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>

#include "ext/glad/glad.h"
Expand Down Expand Up @@ -66,7 +65,6 @@ namespace yocto {
// using directives
using std::mutex;
using std::unordered_map;
using std::unordered_set;
using namespace std::string_literals;

} // namespace yocto
Expand Down
Loading