ULTRIX 4.5 nawk appears to not support local array parameters on user-
defined functions (it is OK for array arguments passed by the caller).
Things seems to work on the first call but on the second call the array
is not empty and other weird behaviours occur.
Using a global array instead seems OK and avoids the problem.
# placing them into dst[0] ... dst[n].
#
# Returns the number of elements.
# placing them into dst[0] ... dst[n].
#
# Returns the number of elements.
-function bucketsort(dst, src, buckets, max, count, i, t)
+function bucketsort(dst, src, max, count, i, t)
+ # Note: ULTRIX 4.5 nawk does not support local array parameters
+ split("", bucketsort_buckets);
+
for (t in src) {
i = length(src[t])
if (i > max) { max = i }
for (t in src) {
i = length(src[t])
if (i > max) { max = i }
+ bucketsort_buckets[i]++
}
for (i = max; i > 0; i--) {
}
for (i = max; i > 0; i--) {
- if (i in buckets) {
- t = buckets[i]
- buckets[i] = count
+ if (i in bucketsort_buckets) {
+ t = bucketsort_buckets[i]
+ bucketsort_buckets[i] = count
count += t
}
}
for (t in src) {
i = length(t = src[t])
count += t
}
}
for (t in src) {
i = length(t = src[t])
+ dst[bucketsort_buckets[i]++] = t
# For optimal results, strings should be added in descending length order.
function add_to_strtab(strtab, str, offsets, pos)
{
# For optimal results, strings should be added in descending length order.
function add_to_strtab(strtab, str, offsets, pos)
{
- if ( (pos = index(strtab, str " ") - 1) < 0) {
- pos = length(strtab)
- if (pos) {
- strtab = strtab " " str
- pos++
- } else {
- strtab = strtab str
- }
+ if ( (pos = index(strtab, str " ") - 1) < 0) {
+ pos = length(strtab)
+ if (pos) {
+ strtab = strtab " " str
+ pos++
+ } else {
+ strtab = strtab str
- offsets[str] = pos
- return strtab
+ }
+
+ offsets[str] = pos
+ return strtab
# placing them into dst[0] ... dst[n].
#
# Returns the number of elements.
# placing them into dst[0] ... dst[n].
#
# Returns the number of elements.
-function bucketsort(dst, src, buckets, max, count, i, t)
+function bucketsort(dst, src, max, count, i, t)
+ # Note: ULTRIX 4.5 nawk does not support local array parameters
+ split("", bucketsort_buckets);
+
for (t in src) {
i = length(src[t])
if (i > max) { max = i }
for (t in src) {
i = length(src[t])
if (i > max) { max = i }
+ bucketsort_buckets[i]++
}
for (i = max; i > 0; i--) {
}
for (i = max; i > 0; i--) {
- if (i in buckets) {
- t = buckets[i]
- buckets[i] = count
+ if (i in bucketsort_buckets) {
+ t = bucketsort_buckets[i]
+ bucketsort_buckets[i] = count
count += t
}
}
for (t in src) {
i = length(t = src[t])
count += t
}
}
for (t in src) {
i = length(t = src[t])
+ dst[bucketsort_buckets[i]++] = t
# placing them into dst[0] ... dst[n].
#
# Returns the number of elements.
# placing them into dst[0] ... dst[n].
#
# Returns the number of elements.
-function bucketsort(dst, src, buckets, max, count, i, t)
+function bucketsort(dst, src, max, count, i, t)
+ # Note: ULTRIX 4.5 nawk does not support local array parameters
+ split("", bucketsort_buckets);
+
for (t in src) {
i = length(src[t])
if (i > max) { max = i }
for (t in src) {
i = length(src[t])
if (i > max) { max = i }
+ bucketsort_buckets[i]++
}
for (i = max; i > 0; i--) {
}
for (i = max; i > 0; i--) {
- if (i in buckets) {
- t = buckets[i]
- buckets[i] = count
+ if (i in bucketsort_buckets) {
+ t = bucketsort_buckets[i]
+ bucketsort_buckets[i] = count
count += t
}
}
for (t in src) {
i = length(t = src[t])
count += t
}
}
for (t in src) {
i = length(t = src[t])
+ dst[bucketsort_buckets[i]++] = t