rb_map #
This file defines additional operations on native rb_maps and rb_sets.
These structures are defined in core in init.meta.rb_map
.
They are meta objects, and are generally the most efficient dictionary structures
to use for pure metaprogramming right now.
Declarations about rb_set
#
filter s P
returns the subset of elements of s
satisfying P
.
mfilter s P
returns the subset of elements of s
satisfying P
,
where the check P
is monadic.
union s t
returns an rb_set containing every element that appears in either s
or t
.
of_list_core empty l
turns a list of keys into an rb_set
.
It takes a user_provided rb_set
to use for the base case.
This can be used to pre-seed the set with additional elements,
and/or to use a custom comparison operator.
of_list l
transforms a list l : list key
into an rb_set
,
inferring an order on the type key
.
sdiff s1 s2
returns the set of elements that are in s1
but not in s2
.
It does so by folding over s2
. If s1
is significantly smaller than s2
,
it may be worth it to reverse the fold.
insert_list s l
inserts each element of l
into s
.
Declarations about rb_map
#
find_def default m k
returns the value corresponding to k
in m
, if it exists.
Otherwise it returns default
.
ifind m key
returns the value corresponding to key
in m
, if it exists.
Otherwise it returns the default value of value
.
zfind m key
returns the value corresponding to key
in m
, if it exists.
Otherwise it returns 0.
Returns the pointwise sum of m1
and m2
, treating nonexistent values as 0.
mfilter P s
filters s
by the monadic predicate P
on keys and values.
mmap f s
maps the monadic function f
over values in s
.
scale b m
multiplies every value in m
by b
.
Declarations about rb_lmap
#
Construct a rb_lmap from a list of key-data pairs
Returns the list of values of an rb_lmap
.
local_list_to_name_set lcs
is the set of unique names of the local
constants lcs
. If any of the lcs
are not local constants, the returned set
will contain bogus names.
local_set_to_name_set lcs
is the set of unique names of the local constants
lcs
. If any of the lcs
are not local constants, the returned set will
contain bogus names.