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

  • Home
  • SEARCH
  • 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 6053189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:00:43+00:00 2026-05-23T08:00:43+00:00

I’ve run into a problem that might require the use of a more unusual

  • 0

I’ve run into a problem that might require the use of a more unusual data structure, but I’m not sure.

Essentially, I want to store URI hostnames in a container, and be able to query the container to tell whether or not a hostname exists in the container. However, if the container contains a higher-level domain of a certain hostname, I want the query to return true if I lookup a lower-level domain. In other words, if the container contains example.com, I’d like to be able to lookup www.example.com, and it would return true. Or, if the container contains foo.example.com, I’d like to be able to lookup bar.foo.example.com, and it would return true.

I’ve thought about this problem, and there doesn’t seem to be any straightforward way to go about doing this. The obvious solution is to just use a regular associative container, like a hash-table or tree (an std::unordered_set or std::set in C++). Upon lookup, I would have to iterate over each segment of the domain name, and keep querying the container to see if it contains each segment. So, if I need to lookup www.example.com, I’d have to do three queries: one for com, one for example.com, and one for www.example.com. As soon as I get a positive, I’d return true, or else return false if none of these are in the container.

This solution is fine, and probably the one I’ll end up going with. Except it doesn’t seem right, since I have to make N queries depending on the length of the host name. Since host names usually don’t have that many segments, I’m not really worried about performance. But I am worried that I should be doing something smarter here, especially because this seems like a problem that someone else has already thought about.

I considered using a more exotic data structure, like a Patrica Trie or some other type of prefix-aware container. I do have a nice library which implements this structure, so it’s not a problem to use it. However, after thinking about the problem, I don’t think a Patricia Trie would help. Tries are designed for circumstances where the key is a prefix, and the values are full-length strings. In my case, the key would often be longer than any value in the container. In other words, my key might be www.example.com, and if the container has example.com, I’d want it to be able to find the example.com. But, Patricia Tries work the opposite way.

So, is a regular associative container the best way to go here? Or what are some other suggestions?

  • 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-05-23T08:00:43+00:00Added an answer on May 23, 2026 at 8:00 am

    A simple solution, reverse the node order (ie. make www.example.com into com.example.www) and stuff that into your Patrica Trie. then you can traverse the trie until you find your match in one go

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is

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.