Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8511347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:57:56+00:00 2026-06-11T03:57:56+00:00

I have custom binary tree class that holds values of template type T (it

  • 0

I have custom binary tree class that holds values of template type T (it could be value or pointer). Each value is encapsulated with number (this number is used for searching in tree). I want to have an std::map inside my tree class fo fast O(1) access to objects without numbers.

template <typename T>
stuct BSTNode 
{
  T value;
  int searchValue;
}

template <typename T>
class BST 
{
  BSTNode<T> * root;
  std::map<T, BSTNode<T>> cache;
  //... etc.
}

Example: I have class instance a inserted in tree under value n. Now I want to get the node associated with this a. I cannot search the tree, because I don’t have n. So I want to use a, and from std::map get node = map[a]. Now I can do node->n.

How can I achieve this? I can override compare method of std::map:

bool operator()(const void * s1, const void * s2) const

But it doesn’t work for value and pointer at the same time: cannot convert parameter 1 from const double to const void *.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:57:58+00:00Added an answer on June 11, 2026 at 3:57 am

    Make a traited comparator:

    template <typename T>
    struct NodeComp
    {
        bool operator<(T const & lhs, T const & rhs) const
        {
            return lhs < rhs;
        }
    };
    
    template <typename U>
    struct NodeComp<U *>
    {
        bool operator<(U * lhs, U * rhs) const
        {
            return *lhs < *rhs;
        }
    };
    

    Now your map can be defined like so:

    template <typename T>
    class BST 
    {
        BSTNode<T> * root;
        std::map<T, BSTNode<T>, NodeComp<T>> cache;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a custom Binary Search Tree, and I have everything
I have a server written in Erlang with a custom binary interface that gets
Updated I have the following custom field class: class Binary(models.Field): __metaclass__ = models.SubfieldBase def
I have a custom PHP extension which compares each byte in a binary data
I have a custom view that extends LinearLayout, with these constructors: public class CustomView
I have written some custom R code that wraps a third-party binary. One of
I have a legacy schema that contains tables with primary keys of type binary(16)
We have an HttpHandler that deals directly with binary posts over HTTP from custom
I have a class that I need to binary serialize. The class contains one
I have various custom binary files stored in perforce and for many of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.