Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:06:13

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file orange/orangeinp/detail/TransformInserter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <unordered_set>
0010 #include <vector>
0011 
0012 #include "orange/transform/VariantTransform.hh"
0013 
0014 namespace celeritas
0015 {
0016 namespace orangeinp
0017 {
0018 namespace detail
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Deduplicate transforms as they're being built.
0023  *
0024  * This currently only works for *exact* transforms rather than *almost exact*
0025  * transforms. We may eventually want to add a "transform simplifier" and
0026  * "transform soft equal".
0027  */
0028 class TransformInserter
0029 {
0030   public:
0031     //!@{
0032     //! \name Type aliases
0033     using VecTransform = std::vector<VariantTransform>;
0034     //!@}
0035 
0036   public:
0037     // Construct with a pointer to the transform vector
0038     explicit TransformInserter(VecTransform* transforms);
0039 
0040     // Construct a transform with deduplication
0041     TransformId operator()(VariantTransform&& vt);
0042 
0043   private:
0044     //// TYPES ////
0045 
0046     struct HashTransform
0047     {
0048         VecTransform* storage{nullptr};
0049         std::size_t operator()(TransformId) const;
0050     };
0051     struct EqualTransform
0052     {
0053         VecTransform* storage{nullptr};
0054         bool operator()(TransformId, TransformId) const;
0055     };
0056 
0057     //// DATA ////
0058 
0059     VecTransform* transform_;
0060     std::unordered_set<TransformId, HashTransform, EqualTransform> cache_;
0061 
0062     //// HELPER FUNCTIONS ////
0063 
0064     //! Get the ID of the next transform to be inserted
0065     TransformId size_id() const { return TransformId(transform_->size()); }
0066 };
0067 
0068 //---------------------------------------------------------------------------//
0069 }  // namespace detail
0070 }  // namespace orangeinp
0071 }  // namespace celeritas