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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:19:50+00:00 2026-06-11T08:19:50+00:00

The standard api does not include an AtomicBitSet implementation. I could roll my own

  • 0

The standard api does not include an AtomicBitSet implementation. I could roll my own on top of AtomicIntegerArray, but would prefer not too.

Is anyone aware of an existing implementation released under a licence compatible with Apache 2? I require only basic operations to set and check bits.

Edit:

The code is both performance and memory critical so I’d like to avoid synchronization or an integer per flag if possible.

  • 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-11T08:19:52+00:00Added an answer on June 11, 2026 at 8:19 am

    I would use an AtomicIntegerArray and I would use 32 flags per integer which would give you the same density as BitSet but without needing locks for thread safety.

    public class AtomicBitSet {
        private final AtomicIntegerArray array;
    
        public AtomicBitSet(int length) {
            int intLength = (length + 31) >>> 5; // unsigned / 32
            array = new AtomicIntegerArray(intLength);
        }
    
        public void set(long n) {
            int bit = 1 << n;
            int idx = (int) (n >>> 5);
            while (true) {
                int num = array.get(idx);
                int num2 = num | bit;
                if (num == num2 || array.compareAndSet(idx, num, num2))
                    return;
            }
        }
    
        public boolean get(long n) {
            int bit = 1 << n;
            int idx = (int) (n >>> 5);
            int num = array.get(idx);
            return (num & bit) != 0;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Standard Java does not offer an object implementing the Queue interface on top of
Background The FreeLing API defines an interface that does not adhere to standard Java
standard power operation ( ** ) in Python does not work for negative power!
Does anybody know a Java implementation of the DRMAA-API that is known to work
I have a list of pictures being pulled from the standard flickr API, and
I have a program in C++, using the standard socket API, running on Ubuntu
is there something like API built atop the standard ProcessBuilder for calling system programs?
I have an Jersey API that returns Odata standard responses and consumes the same.
I'm trying to implement this web api autocomplete in a standard mvc app. http://techbrij.com/987/jquery-ui-autocomplete-asp-net-web-api
I know that the SMS content provider is not part of the public API

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.