in reply to Better algorithm or data structure?

Discard the notion of calling them “booleans.”   They are Work Items, which periodically change state.   And, for each one of these, there is a “cloud” of Interested Parties out there which are waiting for them to become what they are now not.   Those same Interested Parties also need to know when any Work Item ceases to be as it is now.

So, when we introduce a new Interested Party, we associate with it a hash containing, for each Work Item, its last known state.   The Interested Party also contains a count (>= 0) of the number of Work Items it is waiting-upon to change state.   Each Work Item has a list of all of the Interested Parties who are now watching it.

When a Work Item changes state, it notifies all of the Interested Parties, providing its unique-ID and new state.   The Interested Party retrieves the last known state and determines if it has changed.   The appropriate action is determined by an easy four-row state table:
New State Last State Action
TrueTrueTake no action.
TrueFalseSignaled: update last-known-state, decrement wait count. If zero, remove yourself from all interested-parties lists and destroy yourself. (If negative, die!)
FalseFalseTake no action.
FalseTrueUnsignaled: update last-known-state, increment wait count.

You have now completely eliminated the problem of “searching” for anything.

Please notice that I stipulated that Work Items contain a list of references to Interested Parties, but that they provide the parties a unique-id.   This somewhat arbitrary arrangement avoids circular references which can cause headaches for a garbage collector.

  • Comment on Re: Better algorithm or data structure?

Replies are listed 'Best First'.
Re^2: Better algorithm or data structure?
by locked_user sundialsvc4 (Abbot) on Aug 30, 2010 at 15:27 UTC

    Oh, fudge.   If you think the above posting is brilliant, then, “it came from me.”   If not, “I have no idea who just said that.”

    :-D

    As you can see, the Interested Parties simply want to know when the state of a Work Item has changed, and they decide what (if anything...) to do in response to that occurrence.

    The “unique IDs,” which can simply be consecutive arbitrary integers, simply serve as hash-keys.

    There are endless variations on this idea, but I think you get the idea.   And it will produce “orders of magnitude” speed improvements provided that virtual-memory thrashing is not an issue.

      You have now completely eliminated the problem of “searching” for anything.... And it will produce “orders of magnitude” speed improvements

      It's an interesting story, but the devil is in the detail. I've been toying with johngg's idea which is essentially similar in that is uses objects that decide for themselves when something needs to be done. The reality is proving somewhat harder to implement.

      And so far, is well shy of the 2 orders of magnitude improvement achieved by graff, repellent, salva GrandFather.

      At this point, I can say no better than; "Show me the code":)


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Ahh, there is no real need for that.   :-)   TMTOWTDI, and the bottom line is that “a usefully faster solution has been found by someone out there.”   I have not been following this thread closely, anyhow.

        “Anyhow ...”