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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:45:54+00:00 2026-05-18T09:45:54+00:00

My data structure is a linked list of blocks. A block contains 31 elements

  • 0

My data structure is a linked list of blocks. A block contains 31 elements of 4 byte and one 4 byte pointer to the next block or NULL(in summary 128 bytes per block). I add elements from time to time. If the last block is full, I add another block via pointer.

One objective is to use as less memory (= blocks) as possible and having no free space between two elements in a block.

This setting is fix. All code runs on a 32-bit ARM Cortex-A8 CPU with NEON pipeline.

Question:
How to find a specific element in that data structure as quickly as possible?

Approach (right now):
I use sorted blocks and binary search to check for an element (9 bit of the 4 byte are the search criteria). If the desired element is not in the current block I jump to the next block. If the element is not in the last block and the last block is not yet full, I use the result of the binary search to insert the new element (if necessary I make space using memmove within this block). Thus all blocks are always sorted.

Do you have an idea to make that faster?
This is how I search right now: (q->getPosition() is an inline function that just extracts the 9-bit position from the element via “& bitmask”)

do
{
    // binary search algorithm (bsearch)
    // from http://www.google.com/codesearch/
    // p?hl=en#qoCVjtE_vOw/gcc4/trunk/gcc-
    // 4.4.3/libiberty/bsearch.c&q=bsearch&sa=N&cd=2&ct=rc

    base = &(block->points[0]);

    if (block->next == NULL)
    {
        pointsInBlock = pointsInLastBlock;
        stop = true;
    }
    else
    {
        block = block->next;
    }

    for (lim = pointsInBlock; lim != 0; lim >>= 1)
    {
        q = base + (lim >> 1);

        cmp = quantizedPosition - q->getPosition();

        if (cmp > 0)
        {
            // quantizedPosition > q: move right
            base = q + 1;
            lim--;
        }
        else if (cmp == 0)
        {
            // We found the QuantPoint
            *outQuantPoint = q;
            return true;
        }
        // else move left
    }
}
while (!stop);
  • 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-18T09:45:54+00:00Added an answer on May 18, 2026 at 9:45 am

    Since the bulk of the time is spent in the within-block search, that needs to be as fast as possible. Since the number of elements is fixed, you can completely unroll that loop, as in:

    if (key < a[16]){
      if (key < a[8]){
        ...
      }
      else { // key >= a[8] && key < a[16]
        ...
      }
    }
    else { // key >= a[16]
      if (key < a[24]){
        ...
      }
      else { // key >= a[24]
        ...
      }
    }
    

    Study the generated assembly language and single-step it in a debugger, to make sure the compiler’s giving you good code.

    You might want to write a little program to print out the above code, as it will be hard to write by hand, or possibly generate it with macros.

    ADDED: Just noticed your 9-bit search criterion. In that case, just pre-allocate an array of 512 4-byte words, and index it directly. That’s the fastest, and the least code.

    ALSO ADDED: If you need to keep your block structure, there’s another way to do the unrolled binary search. It’s the Jon Bentley method:

    i = 0;
    if (key >= a[i+16]) i += 16;
    if (key >= a[i+ 8]) i +=  8;
    if (key >= a[i+ 4]) i +=  4;
    if (key >= a[i+ 2]) i +=  2;
    if (i < 30 && key >= a[i+ 1]) i +=  1; // this excludes 31
    if (key == a[i]) // then key is found
    

    That’s slower than the if-tree above, because of manipulating i, but could be substantially less code.

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

Sidebar

Related Questions

I have the following data structure (a list of lists) [ ['4', '21', '1',
I just learned about how the Java Collections Framework implements data structures in linked
What is a good data structure for storing phone numbers in database fields? I'm
I want a data structure that will allow querying how many items in last
I'm writing a data structure in C# (a priority queue using a fibonacci heap
Given a data structure (e.g. a hash of hashes), what's the clean/recommended way to
I have a data structure that represents C# code like this: class Namespace: string
Are there any heap data structure implementations out there, fibonacci, binary, or binomial? Reference:
I have a tree data structure that is L levels deep each node has
How do I make a tree data structure in C++ that uses iterators instead

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.