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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:29:35+00:00 2026-06-12T05:29:35+00:00

Is there any way with berkeley db 5.x C API to get all the

  • 0

Is there any way with berkeley db 5.x C API to get
all the records with a key matching a prefix ?

(without scanning the entire database)

Maybe with a Btree prefix comparison custom callback ?

  • 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-12T05:29:37+00:00Added an answer on June 12, 2026 at 5:29 am

    There are two parts to the solution. First, you need to use a custom key comparison function.

    dbp->set_bt_compare(dbp, cmp_fn);
    

    In the comparison function, make it so that the keys with the same prefix are sorted next to each other in the database. This might be as simple as a bunch of less-than compares, so that something like 0x000000000000000000000001 is less than 0x000000000000000000000002.

    To do the search, open a cursor and do a cursor->get() with a DB_SET_RANGE flag. Set your starting key to be at the beginning of the prefix range. Say, if you were looking for keys with the prefix 0x1138, you’d set the key to 0x113800000000000000000000. Then keep calling cursor->get() with DB_NEXT. When you see a key that doesn’t have the 0x1138 prefix, you’re done.

    This technique does not have to scan the entire database, as the initial DB_SET_RANGE call starts the cursor in the right place, and the records are all right next to each other in the tree.

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

Sidebar

Related Questions

Is there any way to use Google's API to retrieve a user's current zipcode
Is there any way in the new windows 8 / windows phone 8 api
Is there any way in Javascript to get the parameters ume modified URL with
Is there any way to get a predefined element with with compass(CSS Framework)? Let's
is there any way to know through code what are all download requests I
Is there any way in vim that I can select the end of all
there any way to get my personal email accounts created in the iphone settings
Is there any way to count all fields with null values for specific record
Is there any way to get a list of properties name from Properties and
Is there any way to list all the files added/removed to repository between two

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.