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

Consider interning small constants #84

Open
arcondello opened this issue Aug 13, 2024 · 0 comments
Open

Consider interning small constants #84

arcondello opened this issue Aug 13, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@arcondello
Copy link
Member

arcondello commented Aug 13, 2024

E.g. something like

class Graph {
    // existing emplacement method
    template <class NodeType, class... Args>
    NodeType* emplace_node(Args&&... args);


    template <std::same_as<ConstantNode> NodeType, std::integral T>
    NodeType* emplace_node(T constant) {
        // if out of range just call the default
        if (constant < 5 || constant > 10) return emplace_node<NodeType>(static_cast<double>(constant));

        // if it's already been created, don't add a new one
        if (interned_constants_[constant - 5] != nullptr) return interned_constants_[constant - 5];

        // create it and add it to interned_constants_
        ...
    }

    std::array<ConstantNode*, 16> interned_constants_;
};
@arcondello arcondello added the enhancement New feature or request label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant