0
我需要一个容器中包含API:如何在枫树中创建地图(std :: map)结构?
addKeyValuePair(containerRef, [key, value])
searchByKey(containerRef, key) #that would return NULL or `value`
如何创建枫木(15)这样的事情?
我需要一个容器中包含API:如何在枫树中创建地图(std :: map)结构?
addKeyValuePair(containerRef, [key, value])
searchByKey(containerRef, key) #that would return NULL or `value`
如何创建枫木(15)这样的事情?
您可能只想将通常的索引编入table。请注意,以前未分配的名称Y
仅因分配给某个索引条目Y[a]
而成为table
。
restart:
Y[a]:=211:
Y[a];
211
Y[b];
Y[b]
assigned(Y[a]);
true
assigned(Y[b]);
false
eval(Y);
table([a = 211])
说了这么多,它只是包裹拿到这里访问Y[b]
回报NULL
时Y[b]
尚未分配你所描述的功能,一个小一点,等
您可以自定义的(或删除)key
为symbol
的错误检查和限制,因为Maple允许更一般地对table
进行索引。
restart:
addKeyValuePair:=proc(containerRef::{indexed,symbol}, L::list)
if nops(L) <> 2 then
error "expecting list with two entries"; end if;
if not type(L[1], symbol) then
error "expecting list with symbol as first entry"; end if;
containerRef[L[1]]:=L[2];
NULL;
end proc:
searchByKey:=proc(containerRef::{indexed,symbol}, key::name)
if assigned(containerRef[key]) then
containerRef[key];
else
NULL;
end if;
end proc:
addKeyValuePair(Y, [a, 4.5]);
searchByKey(Y, a);
4.5
searchByKey(Y, b);
searchByKey(Q, b);
addKeyValuePair(Y, [a, 211]);
searchByKey(Y, a);
211
addKeyValuePair(Y, [c]);
Error, (in addKeyValuePair) expecting list with two entries
addKeyValuePair(Y, [2.34, 211]);
Error, (in addKeyValuePair) expecting list with symbol as first entry
A table
是一种可变数据结构。它的类型为last_name_eval,因此它(有效地)作为过程调用的参数被“引用”传递。