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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:45:21+00:00 2026-05-12T05:45:21+00:00

This question is related to Array of pairs of 3 bit elements This array

  • 0

This question is related to Array of pairs of 3 bit elements
This array has 52 pairs (about 40 bytes), and I want to find the first pair before the specified one that has it’s values different from 0 (used pair).
The obvious solution would be to check each pair < than this one (scan from right to left), but this seems to be very inefficient if there are many unused pairs (set to 0).

This image may explain better the situation:

Pairs 0, 1 and 51 are used.
I want to find the first used pair before 51 (which is 1 here).

I tried tricks like

if(*((int *)&array[arrayPos]) == 0) {
    arrayPos -= sizeof(int);
    pairPos -= ???
}  

The problem here is that subtracting from pairPos is not that simple, because of the 6 bits/pair, so I ended with a lookup table based on some relations between pairPos and arrayPos, and all this made the solution perform like the trivial one.

Is there any way to make this lookup faster ? Another problem is that there is only 1 unused byte… maybe I can make space for another 4. If there were at least 7 I could use a bitmap of the array and it would be much faster to skip over unused pairs.

  • 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-12T05:45:21+00:00Added an answer on May 12, 2026 at 5:45 am

    The best solution I found was:
    1. make the items 1 byte (not 6 bits than before) – thanks Skizz
    2. use a bitmap to see which item is the nearest on the left. This was much faster than going back with the technique described by djna.

    The speed improvements are impressive:
    in one test case, from 13s it’s now 6.5s
    in another one, from 7.4s to 3.6s
    The performance has doubled 😀

    Thanks again for your answers!

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

Sidebar

Ask A Question

Stats

  • Questions 152k
  • Answers 152k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try using it as props.put("fixedString", "true"); Oracle documentation says fixedString… May 12, 2026 at 10:06 am
  • Editorial Team
    Editorial Team added an answer If you setup your ASP.Net membership provider correctly, you can… May 12, 2026 at 10:06 am
  • Editorial Team
    Editorial Team added an answer You can attach additional artifacts using the build-helper-maven-plugin. The configuration… May 12, 2026 at 10:05 am

Related Questions

This question is related to this one . Given this code: char *p =
this question is related to this Multidimensional Associative Array in VB.NET getting the following
This is related to some other questions, such as: this , and some of
I have a custom NSTableView subclass which is bound to a data source (an
Please check this code out it compiles and runs absolutely fine.. The question is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.