hash utilities #289
Aliases: hash utilities
5 verbs · 11 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
to_alist flatten | this none this | rxd | #289 | 13 |
topN | this none this | rxd | #289 | 30 |
bottomN | this none this | rxd | #289 | 30 |
slice | this none this | rxd | #289 | 9 |
merge | this none this | rxd | #289 | 14 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
help_msg | #72 | rc | #361 | list of 11{"This is a set of utilities for parsing and manipulating hashes. See also 'help hashes'.", " ", " :topN(h, ?n = 10) => unsorted list of top n keys, by value", " :bottomN(h, ?n = 10) => unsorted list of bottom n keys, by value", "", " :slice(h, ?i = 1) => $lu:slice(values(h), i)", " :merge(h1, h2, ...) => new hash with all keys/values", "", " :to_alist(h) => {{key1, value1}, {key2, value2}, ...}", " (aka :flatten)", ""} |
aliases | #1 | rc | #361 | {"hash utilities"} |
description | #1 | rc | #361 | <clear> |
object_size | #1 | r | #29 | {3858, 1298434110} |
hidden_verbs | #1 | rc | #361 | <clear> |
phelp_msg | #1 | rc | #361 | <clear> |
weight | #1 | rc | #361 | <clear> |
owner_verbs | #1 | rc | #361 | <clear> |
plural_name | #1 | rc | #361 | <clear> |
client_image | #1 | rc | #361 | <clear> |
listening | #1 | rc | #361 | <clear> |
Ancestry
Ancestors (nearest first): #72 Generic Utilities Package → #1 root
Children: none
Call graph
Source
to_alist flatten
Referenced by
- #6:@pref line 12:
$hu:flatten - #50:@task*s line 233:
$hu:to_alist - #167:do_fire line 29:
$hash_utils:to_alist - #167:summary line 17:
$hash_utils:to_alist - #167:biz_promote line 12:
$hash_utils:to_alist - #167:biz_demote line 16:
$hash_utils:to_alist - #167:biz_listperms line 4:
$hash_utils:to_alist - #167:biz_takeover line 8:
$hash_utils:to_alist - #167:biz_inactives line 5:
$hash_utils:to_alist - #167:biz_voteout line 30:
$hash_utils:to_alist - #167:_old_takeover line 16:
$hash_utils:to_alist - #289:topN line 4:
this:to_alist - #289:bottomN line 4:
this:to_alist
Source
1":to_alist(hash) => List of keys and values e.g. {{key1, value1}, {key2, value2}, ...}"; 2{h, ?sublist = 0} = args; 3l = {}; 4"kvp = key value pair"; 5for kvp in (h) 6{k, v} = kvp; 7if (sublist) 8l = {@l, {k, @v}}; 9else 10l = {@l, {k, v}}; 11endif 12endfor 13return l;
topN
Referenced by
- #96:calc_best line 8:
$hu:topN - #293:reset_top_counts line 33:
$hu:topN - #317:calc_topitems line 16:
$hu:topn - #317:calc_topitems line 25:
$hu:topn
Source
1":topN(HASH h [, INT n]) the top n keys, by value, of h."; 2{h, ?n = 10, ?ytime = 0} = args; 3if (length(h) <= n) 4return this:to_alist(h); 5endif 6topn = {}; 7for entry in (h) 8{key, value} = entry; 9counted = length(topn); 10i = counted; 11while (i) 12yield ytime; 13if (value > topn[i][2]) 14break; 15else 16i = i - 1; 17endif 18endwhile 19if (i) 20if (counted == n) 21topn = {@topn[2..i], entry, @topn[i + 1..$]}; 22else 23topn = {@topn[1..i], entry, @topn[i + 1..$]}; 24endif 25elseif (counted < n) 26topn = {entry, @topn}; 27endif 28yield ytime; 29endfor 30return topn;
bottomN
Referenced by
- #293:reset_top_counts line 42:
$hu:bottomN - #293:add_bottom line 1:
$hu:bottomN
Source
1":bottomN(HASH h [, INT n]) the bottom n keys, by value, of h."; 2{h, ?n = 10, ?ytime = 0} = args; 3if (length(h) <= n) 4return this:to_alist(h); 5endif 6bottomn = {}; 7for entry in (h) 8{key, value} = entry; 9counted = length(bottomn); 10i = counted; 11while (i) 12yield ytime; 13if (value < bottomn[i][2]) 14break; 15else 16i = i - 1; 17endif 18endwhile 19if (i) 20if (counted == n) 21bottomn = {@bottomn[2..i], entry, @bottomn[i + 1..$]}; 22else 23bottomn = {@bottomn[1..i], entry, @bottomn[i + 1..$]}; 24endif 25elseif (counted < n) 26bottomn = {entry, @bottomn}; 27endif 28yield ytime; 29endfor 30return bottomn;
slice
Referenced by
none
Source
1"slice(hash[,index]) returns a list of the index-th elements of the elements of hash, e.g., "; 2" slice([\"foo\" -> {\"z\",1}, \"bar\" -> {\"y\",2}, \"baz\" -> {\"x\",5}], 2) => {1, 2, 5}."; 3"index defaults to 1 and may also be a nonempty list, e.g., "; 4" slice({{\"z\",1,3},{\"y\",2,4}},{2,1}) => {{1,\"z\"},{2,\"y\"}}"; 5{thehash, ?ind = 1} = args; 6if (typeof(thehash) != HASH) 7raise(E_TYPE); 8endif 9return $lu:slice(values(thehash), ind);
merge
Referenced by
- #317:do_scope line 39:
$hu:merge
Source
1":merge(HASH a, HASH b, ...) -> HASH with keys/values from all given hashes. If there are duplicate keys, the values from later hashes override values from earlier hashes in the arg list."; 2result = []; 3for h in (args) 4if (typeof(h) != HASH) 5raise(E_TYPE); 6endif 7if (!h) 8continue; 9endif 10for kv in (h) 11result[kv[1]] = kv[2]; 12endfor 13endfor 14return result;