Ilya Zakharevich on Wed, 24 Jan 2024 10:19:32 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Missing functionality in forvec() |
I want to use forwec() in a complicated algorithms needing a lot of cached data. The caches should be recalculated on backtracking. Here I consider forvec() as if it is traversing-in-order an “ordered rooted tree”. While forvec() takes a lot of workload under the cover, with forvec() it is a PITA to detect backtracking. On the other hand, I can see that with an extra argument taking an (optional) variable reference 'v, and reporting the details of backtracking in v, the life would be much easier! The docs could go like this (I would need only one of these 3 flavors of reporting; two others are added in anticipation of usability in other situations): Let n be the number of tail counters which wrapped around after the preceding iteration, and m be the number which will wrap around on the next iteration. If 'v was a small/v/vector at start, put n and m into the first two components; otherwise report n or -m, preferring the non-0 value. (For what follows, note that with flag=2 both n and m may be non-0 even if the trailing ranges are not of length 1.) If 'v was 0 at start, prefer the largest of n and m, otherwise prefer positive or negative depending on the sign of 'v at start. Can it be useful in other situations than what I have in mind? (This improving the chance of it being implemented. ;―]) Thanks, Ilya