# Like GNU awk's asort() but works with any awk(1)
# NB: Named _asort() to prevent conflict with GNU awk
function _asort(src, dest)
for (i in src) dest[++nitems] = src[i]
for (i = 1; i <= nitems; k = i++) {
while ((k > 0) && (dest[k] > val)) {
############################################################
# split(string, array, /,/)
# n = _asort(array, sorted_array)
# for (i = 1; i <= n; i++)
# sorted_string = sorted_string "," sorted_array[i]
# sub(/^,/, "", sorted_string)
# print sorted_string # produces "123,abc"
############################################################
# Like GNU awk's asorti() but works with any awk(1)
# NB: Named _asorti() to prevent conflict with GNU awk
function _asorti(src, dest)
for (i in src) dest[++nitems] = i
for (i = 1; i <= nitems; k = i++) {
while ((k > 0) && (dest[k] > idx)) {
# Sample _asorti() usage:
############################################################
# foo["abc"] = 1 # value ignored
# foo["123"] = 1 # value ignored
# n = _asorti(foo, sorted_indices)
# for (i = 1; i <= n; i++)
# print sorted_indices[i]
############################################################