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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:23:12+00:00 2026-06-03T06:23:12+00:00

I have a scenario at work where we have several different tables of data

  • 0

I have a scenario at work where we have several different tables of data in a format similar to the following:

Table Name: HingeArms
Hght   Part #1       Part #2
33     S-HG-088-00   S-HG-089-00
41     S-HG-084-00   S-HG-085-00
49     S-HG-033-00   S-HG-036-00
57     S-HG-034-00   S-HG-037-00

Where the first column (and possibly more) contains numeric data sorted ascending and represents a range to determine the proper record of data to get (e.g. height <= 33 then Part 1 = S-HG-088-00, height <= 41 then Part 1 = S-HG-084-00, etc.)

I need to lookup and select the nearest match given a specified value. For example, given a height = 34.25, I need to get second record in the set above:

41     S-HG-084-00   S-HG-085-00

These tables are currently stored in a VB.NET Hashtable “cache” of data loaded from a CSV file, where the key for the Hashtable is a composite of the table name and one or more columns from the table that represent the “key” for the record. For example, for the above table, the Hashtable Add for the first record would be:

ht.Add("HingeArms,33","S-HG-088-00,S-HG-089-00")

This seems less than optimal and I have some flexibility to change the structure if necessary (the cache contains data from other tables where direct lookup is possible… these “range” tables just got dumped in because it was “easy”). I was looking for a “Next” method on a Hashtable/Dictionary to give me the closest matching record in the range, but that’s obviously not available on the stock classes in VB.NET.

Any ideas on a way to do what I’m looking for with a Hashtable or in a different structure? It needs to be performant as the lookup will get called often in different sections of code. Any thoughts would be greatly appreciated. Thanks.

  • 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-03T06:23:13+00:00Added an answer on June 3, 2026 at 6:23 am

    A hashtable is not a good data structure for this, because items are scattered around the internal array according to their hash code, not their values.

    Use a sorted array or List<T> and perform a binary search, e.g.

    Setup:

    var values = new List<HingeArm>
    {
        new HingeArm(33, "S-HG-088-00", "S-HG-089-00"),
        new HingeArm(41, "S-HG-084-00", "S-HG-085-00"),
        new HingeArm(49, "S-HG-033-00", "S-HG-036-00"),
        new HingeArm(57, "S-HG-034-00", "S-HG-037-00"),
    };
    
    values.Sort((x, y) => x.Height.CompareTo(y.Height));
    
    var keys = values.Select(x => x.Height).ToList();
    

    Lookup:

    var index = keys.BinarySearch(34.25);
    if (index < 0)
    {
        index = ~index;
    }
    
    var result = values[index];
    // result == { Height = 41, Part1 = "S-HG-084-00", Part2 = "S-HG-085-00" }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problems to get generics to work in the following scenario: Delphi provides
I have a very simple scenario which I cannot get to work. I am
I'm struggling with getting IOC to work in a remoting scenario. I have my
I have scenario where I have to use the same XSD element for different
If I have a java project that consists of several different types of files
I'm doing some work with strings, and I have a scenario where I need
Here's my scenario: I have a page containing several links; each link is meant
Here is the scenario: I have several .pfx files and I need to store
I have scenario where I need to host a web service (WCF) on Azure
I have scenario, I have two update panels on the page (both have update

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.