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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:50:10+00:00 2026-05-27T22:50:10+00:00

I have a RuleTree data structure which represents a tree of rules that are

  • 0

I have a RuleTree data structure which represents a tree of rules that are used to process incoming data items.

  • The RuleTree is currently an immutable data structure containing an arbitrary number of (possibly nested) rules.
  • There are multiple threads which will be simultaneously applying the same RuleTree to different input data items
  • The RuleTree is applied to input data in one or more phases. It’s up to the calling code to decide which phases to apply.

The typical control flow will be something like:

ruleTree.applyStage1(data);
..
// other stuff happens
..
ruleTree.applyStage2(data);
..
// other stuff happens
..
ruleTree.applyStage3(data);

This currently works fine. However, I now have a requirement to calculate some additional state information during RuleTree processing (e.g. counting the number of matches for a specific rule in the tree). As far as I can see it, I have a few options:

  • Make the RuleTree mutable and enable it to store the state information which can be read back later. This will make concurrency trickier however since different threads will need different copies of the RuleTrees.
  • Add thread-local state to RuleTrees – so that the state information can be calculated and stored within the RuleTree, but different threads won’t trample upon each other’s state information. However this means that all phases must be guaranteed to run on the same thread.
  • Have a separate object for state information that can be passed as an extra parameter to the ruletree, e.g. ruleTree.applyStage1(data, state). This keeps the RuleTrees nice and immutable, but makes using them more complex for the caller since the calling code now has to setup and manage the state data separately.

Which approach is likely to be best and why?

  • 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-27T22:50:11+00:00Added an answer on May 27, 2026 at 10:50 pm

    Use the “separate object for state information” approach, because it does not suffer from the flaws inherent in the other approaches you are considering. What’s more, the chief flaw of the “separate object” model, that it requires the user to pass the state to every method of RuleTree, can easily be dealt with.

    Consider a proxy for RuleTree. I’ll use Ruby as a workable approximation for pseudocode:

    class RuleTreeProxy
    
      def initialize(ruleTree)    # Constructor
        @ruleTree = RuleTree
        @state = RuleTreeState.new
      end
    
      def state
        return @state
      end        
    
      def applyStage1(data)
        @rule_tree.applyStage1(@state, data)
      end
    
      def applyStage2(data)
        @rule_tree.applyStage2(@state, data)
      end
    
      # etc.
    
    end
    

    @ denotes an object member variable.

    Anyone needing to use RuleTree creates a RuleTreeProxy and calls it instead:

    proxy = RuleTreeProxy.new(ruleTree)
    proxy.applyStage1(data)
    proxy.applyStage2(data)
    ...
    

    The state object contains accessors to retrieve useful information about the processing done by RuleTree:

    matches = proxy.state.numberOfMatches
    

    If you require that the different phases can be done in different threads, then either ensure that no two threads will attempt to operate on a RuleTreeProxy instance at the same time, or add appropriate synchronization to RuleTreeProxy.

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

Sidebar

Related Questions

Have some data in a sybase image type column that I want to use
Have anyone used Redmine Documentor which lets you convert PHP to HTML to Redmine
Have a xml data like <Items><Item><name>test1</name></Item><Item><name>test2</name></Item></Items> Looks like jaxb cannot unmashall this when defining
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have created simple Ajax enabled contact forms before that have around 12 fields -
Have a LinqtoSql query that I now want to precompile. var unorderedc = from
Have you used NPanday to integrate Visual Studio with Apache Maven ? If so,
Have a bunch of WCF REST services hosted on Azure that access a SQL
Have some dates in my local Oracle 11g database that are in this format:

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.