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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:19:23+00:00 2026-05-24T19:19:23+00:00

I have a tree, A / \ B C /\ \ D E F

  • 0

I have a tree,

     A
    / \
   B   C
  /\    \
 D  E    F

represented as a list,

(A (B (D) (E)) (C (F)))

It actually is a very large tree so what I would like to do is start the search if I can’t find what I am looking for in say 100 ms save state, return, do some house keeping and then call search again and continue where I left off. Basically simulation I am working with is giving me a certain amount of time not enough to complete the search. I am looking for ideas/techniques on how to achive this? (in Clojure, Java)

  • 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-24T19:19:24+00:00Added an answer on May 24, 2026 at 7:19 pm

    Threading is likely to be the easiest solution, but it’s not very difficult to manage it yourself on a single thread. “Simulation” environments that only give you 100ms often don’t allow any new threads, so this is an alternative.

    The basic idea is to create a closure representing the work that needs to be done to finish the task, and return that instead of a result if you don’t have time to finish. Here’s a sketch: it adds a sequence of numbers up, and gets interrupted every ten operations instead of every 100ms.

    (let [timer (atom 9)]
      (defn keep-going? []
        (not= 0 (swap! timer #(mod (inc %) 10)))))
    
    (defn saving-addition [sum xs]
      (if-let [[x & more] (seq xs)]
        (let [next-thunk (fn [] (saving-addition (+ x sum) more))]
          (if (keep-going?)
            (next-thunk)
            next-thunk))
        sum))
    
    (defn monitor [xs]
      (loop [thunk (saving-addition 0 xs)]
        (if (fn? thunk)
          (do
            (println "Saving execution state")
            (recur (thunk)))
          thunk)))
    
    user> (monitor (range 25))
    Saving execution state
    Saving execution state
    Saving execution state
    300
    

    Edit: Because Clojure does not have tail-call optimization, creating a thunk and then calling it uses up stack. If, as is likely, you are able to execute more than a few thousand steps before you need to be interrupted, you will get a stack overflow. The only realistic solution is to duplicate the body of the thunk in both a recur and in the continuation, like

    (defn saving-addition [sum xs]
      (if-let [[x & more] (seq xs)]
        (let [sum (+ x sum)]
          (if (keep-going?)
            (recur sum more)
            #(saving-addition sum more)))
        sum))
    

    You could probably abstract this out with a macro if you had to write multiple such “suspendable” functions.

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

Sidebar

Related Questions

I have a tree structure in memory that I would like to render in
In mysql, I have a tree that is represented using the adjacency list model.
I have a simple tree structure represented like this: Node { int Id; int
I have an unordered tree. Each node represents a task that can be done
I have a tree of active record objects, something like: class Part < ActiveRecord::Base
I have a list box that contains items that are represented by a single
I have a list that looks like (A (B (C D)) (E (F))) which
Assume I have a mathematical expression in a tree form in OCaml. It's represented
I have a problem where the data is represented in form of a tree
If i have a tree structure whose nodes can have zero to many children,

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.