forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransformInserter.hh
72 lines (60 loc) · 2.01 KB
/
TransformInserter.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//----------------------------------*-C++-*----------------------------------//
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file orange/orangeinp/detail/TransformInserter.hh
//---------------------------------------------------------------------------//
#pragma once
#include <unordered_set>
#include <vector>
#include "orange/transform/VariantTransform.hh"
namespace celeritas
{
namespace orangeinp
{
namespace detail
{
//---------------------------------------------------------------------------//
/*!
* Deduplicate transforms as they're being built.
*
* This currently only works for *exact* transforms rather than *almost exact*
* transforms. We may eventually want to add a "transform simplifier" and
* "transform soft equal".
*/
class TransformInserter
{
public:
//!@{
//! \name Type aliases
using VecTransform = std::vector<VariantTransform>;
//!@}
public:
// Construct with a pointer to the transform vector
explicit TransformInserter(VecTransform* transforms);
// Construct a transform with deduplication
TransformId operator()(VariantTransform&& vt);
private:
//// TYPES ////
struct HashTransform
{
VecTransform* storage{nullptr};
std::size_t operator()(TransformId) const;
};
struct EqualTransform
{
VecTransform* storage{nullptr};
bool operator()(TransformId, TransformId) const;
};
//// DATA ////
VecTransform* transform_;
std::unordered_set<TransformId, HashTransform, EqualTransform> cache_;
//// HELPER FUNCTIONS ////
//! Get the ID of the next transform to be inserted
TransformId size_id() const { return TransformId(transform_->size()); }
};
//---------------------------------------------------------------------------//
} // namespace detail
} // namespace orangeinp
} // namespace celeritas