Giter Site home page Giter Site logo

Comments (3)

kinow avatar kinow commented on August 19, 2024

Permanent link for the code mentioned https://github.com/jhalterman/failsafe/blob/119c6c88a82df906134ab1b06459fe8bebdadaf0/src/main/java/net/jodah/failsafe/internal/util/CircularBitSet.java#L33
(won't change after a commit)

from failsafe.

chhsiao90 avatar chhsiao90 commented on August 19, 2024

Hi @na389 ,

Because CircularBitSet should keep latest execution result while the threshold size became smaller.
ex:
while CircularBitSet size changed from 10 to 4, the new CircularBitSet will only take the execution result from old bitSet from 6 to 10.

from failsafe.

jhalterman avatar jhalterman commented on August 19, 2024

@na389 I just pushed a commit that re-works this a bit, so hopefully it's clear now what's going on. The basic algo is:

  • Determine how many bits to copy.
  • Determine the index to start copying from.
  • Loop and copy the bits. Since the data structure is circular, looping may require going back to 0.

Since we want to copy the n most recent bits, the start index is just the end of the logical bitset (nextIndex) minus the number of bits to copy. But since the data structure is circular, if this number ends up being negative (when the number of bits to copy is greater than the nextIndex), then we need to offset by the size of the bitset.

You can check out some of the test cases for this stuff which assert that BitSets values are copied as expected given various nextIndex values (which may vary as the BitSet is circularly filled and refilled).

from failsafe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.