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 8966911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:07:32+00:00 2026-06-15T17:07:32+00:00

The problem I have to solve is that I have to input IP address

  • 0

The problem I have to solve is that I have to input IP address prefixes and that data associated with them in a tree so they can be queried later. I’m reading these addresses from a file and the file may contain as many as 16 million records and the file could have duplicates and i have to store those too.

I wrote my own binary search tree, but learned that a TreeMap in Java is implemented using a Red Black tree, but a TreeMap can’t contain duplicates.

I want the query to take O(logn) time.

The data structure needs to be in Ram, so I’m also not sure how I’m going to store 16 million nodes.

I wanted to ask: Would it be too much of a performance hit using a library like guava to insert the Ips in Multi-maps? Or is there a better way to do this?

  • 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-15T17:07:33+00:00Added an answer on June 15, 2026 at 5:07 pm

    Using a built in library, which is tested documented and well maintained is usually a good practice.

    It will also help you learn more about guava. Once you start using it “for just one thing”, you will most likely realize there is much more you can use to make your life a bit easier.

    Also, an alternative is using a TreeMap<Key,List<MyClass>> rather then TreeMap<Key,MyClass> as a custom implementation of a Multimap.


    Regarding memory – you should try to minimize your data as much as possible (use efficient data structures, no need for “wasty” String, for example for storing IPs, there are cheaper alternatives, exploit them.

    Also note – the OS will be able to offer you more memory then the RAM you have, by using virtual memory (practically for 64bits machine – it is most likely to be more then enough). However, it will most likely be less efficient then a DS dedicated for disk (such as B+ trees, for example).


    Alternatives:

    As alternatives to the TreeMap – you might be interested in other data structures (each with its advantages and disadvantages):

    • hash table – implemented as HashMap in java. Your type will then beHashMap<Key,List<Value>>. It allows O(1) average case query, but might decay to O(n) worst case. It also does not allow efficient range queries.
    • trie or its more space efficient version – radix tree. Allows O(1) access to each key, but is usually less space efficient then the alternatives. With this approach, you will implement the Map interface with the DS, and your type will be Map<Key,List<Value>>
    • B+ tree, which is much more optimized for disk – if your data is too large to fit in RAM after all.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem that i can't solve ! (sqlite3, but i think it
I have a problem, that I can't solve. I am writing an application that
I have a strange problem that I can't seem to solve. I've quite a
I have a little problem and I'm hopping that you can help me solve
I have a problem that i cant solve :( I have a user control
i have a problem, that i don't know how to solve it. i have
I have the following problem that I want to solve in awk. I have
I have a strange problem that I could not solve. When I try to
I have a simple problem that i cannot solve. I have a dictionary: aa
I have the following problem that the standard library doesn't solve well, and I'm

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.