我想使用像HashTable这样的结构。Wolfram Mathematica也有类似的结构吗?
发布于 2009-09-08 04:49:26
我要说的是,你能得到的最相似的结构是sparse arrays。
发布于 2009-09-09 02:04:05
发布于 2011-12-01 00:34:49
我制作了Dictionary.m模块,它包含:
DictHasKey = Function[
{
dict,
key
},
ValueQ[dict[key]]
]
DictAddKey = Function[
{
dict,
key,
value
},
If[
DictHasKey[dict,key],
Print["Warning, Dictionary already has key " <> ToString[key]]
];
dict[key] = value;
]
DictKeys = Function[
{
dict
},
res = {};
ForEach[DownValues[dict], Function[{dictKeyDescr},
res = Append[res, ((dictKeyDescr[[1]]) /. dict -> neverUsedSymbolWhatever)[[1, 1]]];
]];
res
]
DictValues = Function[
{
dict
},
res = {};
ForEach[DownValues[dict], Function[{dictKeyDescr},
res = Append[res, dictKeyDescr[[2]]];
]];
res
]
DictKeyValuePairs = Function[
{
dict
},
res = {};
ForEach[DownValues[dict], Function[{dictKeyDescr},
res = Append[res, {((dictKeyDescr[[1]]) /. dict -> neverUsedSymbolWhatever)[[1, 1]], dictKeyDescr[[2]]}];
]];
res
]
ForEach = Function[
{
list,
func
},
len = Length[list];
For[i = 1, i <= len, i++,
func[
list[[i]]
];
];
]
https://stackoverflow.com/questions/1392007
复制相似问题