diff --git a/crnlib/allocator.h b/crnlib/allocator.h new file mode 100644 index 00000000..29eaadaa --- /dev/null +++ b/crnlib/allocator.h @@ -0,0 +1,36 @@ +#pragma once +#include "crn_mem.h" + +namespace crnlib +{ + template + class allocator + { + public: + using value_type = T; + template allocator(allocator const&) noexcept {} + allocator() noexcept {}; + + value_type* allocate(std::size_t n) + { + return static_cast(crnlib_malloc(n * sizeof(T))); + } + + void deallocate(value_type* p, std::size_t) noexcept + { + crnlib_free(p); + } + }; + + template + bool operator==(allocator const&, allocator const&) noexcept + { + return true; + } + + template + bool operator!=(allocator const& x, allocator const& y) noexcept + { + return !(x == y); + } +} \ No newline at end of file diff --git a/crnlib/crn_dxt_hc.cpp b/crnlib/crn_dxt_hc.cpp index a099be88..825f0c0b 100644 --- a/crnlib/crn_dxt_hc.cpp +++ b/crnlib/crn_dxt_hc.cpp @@ -716,7 +716,7 @@ void dxt_hc::determine_color_endpoints() { m_pTask_pool->queue_task(&Node::sort_task, i, &nodes[i]); m_pTask_pool->join(); - std::priority_queue queue; + std::priority_queue>> queue; for (uint i = 0; i < nodes.size(); i++) queue.push(nodes[i]); @@ -1055,7 +1055,7 @@ void dxt_hc::create_color_selector_codebook() { m_pTask_pool->queue_task(&SelectorNode::sort_task, i, &nodes[i]); m_pTask_pool->join(); - std::priority_queue queue; + std::priority_queue>> queue; for (uint i = 0; i < nodes.size(); i++) queue.push(nodes[i]); @@ -1213,7 +1213,7 @@ void dxt_hc::create_alpha_selector_codebook() { m_pTask_pool->queue_task(&SelectorNode::sort_task, i, &nodes[i]); m_pTask_pool->join(); - std::priority_queue queue; + std::priority_queue>> queue; for (uint i = 0; i < nodes.size(); i++) queue.push(nodes[i]); diff --git a/crnlib/crn_tree_clusterizer.h b/crnlib/crn_tree_clusterizer.h index d6785c3b..1c0a342e 100644 --- a/crnlib/crn_tree_clusterizer.h +++ b/crnlib/crn_tree_clusterizer.h @@ -4,6 +4,7 @@ #include "crn_matrix.h" #include "crn_threading.h" #include +#include "allocator.h" namespace crnlib { template @@ -33,7 +34,7 @@ class tree_clusterizer { void split_alternative_node_task(uint64, void* pData_ptr) { split_alternative_node_task_params* pParams = (split_alternative_node_task_params*)pData_ptr; - std::priority_queue node_queue; + std::priority_queue>> node_queue; uint begin_node = pParams->alternative_node, end_node = begin_node, splits = 0; m_nodes[end_node] = m_nodes[pParams->main_node]; @@ -78,7 +79,7 @@ class tree_clusterizer { root.m_variance = (float)(ttsum - (root.m_centroid.dot(root.m_centroid) / root.m_total_weight)); root.m_centroid *= (1.0f / root.m_total_weight); - std::priority_queue node_queue; + std::priority_queue>> node_queue; uint begin_node = 0, end_node = begin_node, splits = 0; m_nodes[end_node] = root; node_queue.push(NodeInfo(end_node, root.m_variance)); @@ -89,7 +90,7 @@ class tree_clusterizer { while (splits < max_splits && node_queue.size() != num_tasks && split_node(node_queue, end_node, pTask_pool)) splits++; if (node_queue.size() == num_tasks) { - std::priority_queue alternative_node_queue = node_queue; + std::priority_queue>> alternative_node_queue = node_queue; uint alternative_node = max_splits << 1, alternative_max_splits = max_splits / num_tasks; crnlib::vector params(num_tasks); for (uint task = 0; !alternative_node_queue.empty(); alternative_node_queue.pop(), alternative_node += alternative_max_splits << 1, task++) { @@ -193,7 +194,8 @@ class tree_clusterizer { } } - bool split_node(std::priority_queue& node_queue, uint& end_node, task_pool* pTask_pool = 0) { + bool split_node(std::priority_queue>>& node_queue, + uint& end_node, task_pool* pTask_pool = 0) { if (node_queue.empty()) return false; diff --git a/crnlib/crnlib.2010.vcxproj b/crnlib/crnlib.2010.vcxproj index ec5d528f..59021301 100644 --- a/crnlib/crnlib.2010.vcxproj +++ b/crnlib/crnlib.2010.vcxproj @@ -550,6 +550,7 @@ +