[q-lang-cvs] qcalc qcalc.q,1.125,1.126
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2007-11-11 00:33:09
|
Update of /cvsroot/q-lang/qcalc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17405 Modified Files: qcalc.q Log Message: remove obsolete code, optimizations Index: qcalc.q =================================================================== RCS file: /cvsroot/q-lang/qcalc/qcalc.q,v retrieving revision 1.125 retrieving revision 1.126 diff -C2 -d -r1.125 -r1.126 *** qcalc.q 10 Nov 2007 22:49:07 -0000 1.125 --- qcalc.q 11 Nov 2007 00:33:04 -0000 1.126 *************** *** 2834,2840 **** where (S,_,_) = get EVAL!(I,J); ! /* Recompute everything. */ ! compute_all V = begin_compute || do submit V || collect_results emptyhdict V || end_compute_test; --- 2834,2840 ---- where (S,_,_) = get EVAL!(I,J); ! /* Recompute the given cells. */ ! compute V = begin_compute || do submit V || collect_results emptyhdict V || end_compute_test; *************** *** 2956,2994 **** otherwise; - /* Recompute a single cell, or a collection of cells, and all cells depending - on these. */ - - compute U V = begin_compute || - do submit_clear U || collect_results emptyhdict U || - end_compute_test - where U = all_deps U V, U = filter (member (get EVAL)) U; - - /* Same as above, but exclude GUI elements unless they are triggered. */ - - compute2 U V = //printf " -> %s\n" $ str U || - begin_compute || - do submit_clear U || collect_results emptyhdict U || - end_compute_test - where //_ = printf "*** triggered updates: %s" $ str U, - U = all_deps2 U V, U = filter (member (get EVAL)) U; - - all_deps (I,J) V - = all_deps [(I,J)] V; - all_deps U V = filter (member D) V - where D = hdict $ map (flip pair true) U, - D = foldl add_deps D V; - - add_deps D (I,J) - where (S,X,DEPS) = get EVAL!(I,J): - = insert D ((I,J),true) if any (member D) DEPS; - = D otherwise; - - all_deps2 (I,J) V - = all_deps2 [(I,J)] V; - all_deps2 U V = filter (D!) $ filter (member D) V - where W = map (neg is_gui_elem) U, - D = hdict $ zipwith pair U W, - D = foldl add_deps D V; - /* Reformat floating point numbers for the given precision. */ --- 2956,2959 ---- *************** *** 3007,3011 **** /* Process cell values after edits or after loading a new file. */ ! process_all = compute_all $ eval_list $ sort indexcmp $ keys $ get CELLS if check_interp; --- 2972,2977 ---- /* Process cell values after edits or after loading a new file. */ ! process_all = compute $ eval_list (cst true) $ sort indexcmp $ keys $ ! get CELLS if check_interp; *************** *** 3013,3019 **** clear_cell (I,J) || // do the necessary reevaluations ! if check_interp then compute (I,J) V ! where V = eval_list (I,J), ! V = dropwhile (<>(I,J)) V; process (I,J) S = insert_eval (I,J;S,'X,DEPS) || --- 2979,2984 ---- clear_cell (I,J) || // do the necessary reevaluations ! if check_interp then compute V ! where V = eval_list (cst true) (I,J); process (I,J) S = insert_eval (I,J;S,'X,DEPS) || *************** *** 3027,3034 **** clear_cell (I,J) || set_cell (I,J) S || ! if check_interp then compute (I,J) V where S = qt TABLE "text" (I,J), _ = delete_eval (I,J), ! V = eval_list (I,J); process_gui (I,J) X --- 2992,2999 ---- clear_cell (I,J) || set_cell (I,J) S || ! if check_interp then compute V where S = qt TABLE "text" (I,J), _ = delete_eval (I,J), ! V = eval_list (cst true) (I,J); process_gui (I,J) X *************** *** 3037,3043 **** if checkval X then submit_val (I,J) X || // do the necessary reevaluations ! if check_interp then compute (I,J) V ! where V = eval_list (I,J), ! V = dropwhile (=(I,J)) $ dropwhile (<>(I,J)) V, X = gui_getval X; --- 3002,3007 ---- if checkval X then submit_val (I,J) X || // do the necessary reevaluations ! if check_interp then compute V ! where V = eval_list (cst false) (I,J), X = gui_getval X; *************** *** 3057,3065 **** otherwise; ! process_sel W = if check_interp then compute W V where (C,E) = foldl process1 (get CELLS,get EVAL) W, _ = set_cells C || set_eval E, W = map (flip (flip sub 0) 1) W, ! V = eval_list W if not null W and then check_interp; --- 3021,3029 ---- otherwise; ! process_sel W = if check_interp then compute V where (C,E) = foldl process1 (get CELLS,get EVAL) W, _ = set_cells C || set_eval E, W = map (flip (flip sub 0) 1) W, ! V = eval_list (cst true) W if not null W and then check_interp; *************** *** 3082,3121 **** otherwise; ! process_sel2 W = if check_interp then compute2 W V where //_ = printf "*** pending updates: %s\n" $ str W, (C,E) = foldl process2 (get CELLS,get EVAL) W, _ = set_cells C || set_eval E, W = map (flip (flip sub 0) 1) W, ! V = eval_list W if not null W and then check_interp; ! clear_sel W = do clear_cell W || compute W V where _ = delete_cells W || delete_eval W, ! V = eval_list W if not null W and then check_interp; /* Compute the evaluation order. The present implementation uses a depth-first search algorithm (more precisely, the reversal of a depth-first postorder) ! starting from a given node or list of nodes. This works ok with cyclic ! dependencies, but may consider them in an apparently random order. (If you ! take a closer look you will find that the order is not completely random, ! but always considers forward edges in the dependency graph in the order of ! the target (dependent) cells, where cells are ordered first by their row, ! then by their column indices.) The result is a list V containing the ! indices of cells in the order in which they should be evaluated. */ ! eval_list (I,J) = eval_list [(I,J)]; ! eval_list V = dfs_list V; ! dfs_list [] = []; ! dfs_list V = //if not null V then printf "DFS: %s\n" $ str V || ! V ! where V = filter (member (get EVAL)) $ dfs V; ! dfs V = Xs where (_,Xs) = foldl search (emptyhdict,[]) $ reverse V; ! search (V,Xs) X = (V,Xs) if member V X; ! = (V,[X|Xs]) where W:List = get XREF!X, ! (V,Xs) = foldl search (insert V (X,true),Xs) W; = (V,[X|Xs]) otherwise; --- 3046,3099 ---- otherwise; ! process_sel2 W = if check_interp then compute V where //_ = printf "*** pending updates: %s\n" $ str W, (C,E) = foldl process2 (get CELLS,get EVAL) W, _ = set_cells C || set_eval E, W = map (flip (flip sub 0) 1) W, ! // Exclude all toplevel GUI elements from this list ! // (unless they are triggered by other elements). ! V = eval_list (neg is_gui_elem) W if not null W and then check_interp; ! clear_sel W = do clear_cell W || compute V where _ = delete_cells W || delete_eval W, ! V = eval_list (cst true) W if not null W and then check_interp; /* Compute the evaluation order. The present implementation uses a depth-first search algorithm (more precisely, the reversal of a depth-first postorder) ! starting from a given "root" node (cell index) or list of root nodes. ! This works ok with cyclic dependencies, but may consider them in an ! arbitrary order, except that root nodes are guaranteed to come first ! (unless they have already been triggered while searching another root ! node). (If you take a closer look you will find that the ordering of cycle ! nodes is in fact not completely arbitrary, but always considers forward ! edges in the dependency graph in the order of the target (dependent) cells, ! where cells are ordered first by their row, then by their column indices.) ! The result is a list V containing the indices of cells in the order in ! which they should be evaluated. ! The P argument of eval_list is a predicate to be applied to the root nodes, ! in order to determine whether they should be included in the result list. ! If this function returns false, then the corresponding root node is ! excluded from the result list, although it may still trigger other ! elements. This is used to filter out updated GUI elements which shouldn't ! actually be recomputed (cf. process_sel2). */ ! ! eval_list P (I,J) ! = eval_list P [(I,J)]; ! eval_list P [] = []; ! eval_list P V = printf "DFS: %s\n" $ str V || ! V where V = filter (member (get EVAL)) $ dfs P V; ! ! dfs P V = Xs where (_,Xs) = foldl (search P) (emptyhdict,[]) V; ! search P (V,Xs) X ! = (V,Xs) if member V X; ! = (V,if P X then [X|Xs] else Xs) where W:List = get XREF!X, ! (V,Xs) = foldl (search (cst true)) ! (insert V (X,true),Xs) W; = (V,[X|Xs]) otherwise; |