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,因此它(有效地)作爲過程調用的參數被「引用」傳遞。