array sorting checked in

Frank Ch. Eigler fche@redhat.com
Fri Sep 23 17:57:00 GMT 2005


hunt wrote:

> [...] I checked in several new functions to the runtime.
> _stp_map_sort(MAP map, int keynum, int dir) [...]

OK.  It seems to me that the most straightforward way to expose this
in the language would be as a modifier for the "foreach" statement,
something like:

        foreach ([x,y] in sort(array)) {
          do_something_with (array[x,y])
          if (i++ > 10) break
        }

A related modifier could serve as an iteration count limiter, which
would presumably save sorting time.  Given the implementation's likely
performance, it would be wise to penalize sorting by an extra
actioncount, to represent its cost.

Adding a plain "sort <array>" operation would be of only limited
applicability, considering the possibility of concurrent/subsequent
modifications, invalidating the sorted property.  foreach should holds
a lock (but see bug #1275) on the array during iteration, which if
finagled properly, would protect the sorted property for the duration
of iteration.


- FChE



More information about the Systemtap mailing list