我想在我的 C 代码 (XS) 中使用 Perl 哈希作为一个集合,所以我只需要将键保存在哈希中。是否可以存储诸如 null 或其他常量值之类的内容以避免创建不必要的值?
像这样的东西:
int add_value(HV *hash, SV *value)
{
// just an example of key
char key[64];
sprintf(key, "%p", value);
if (hv_exists(hash, key, strlen(key)) return 0;
// here I need something instead of ?
return hv_stores(hash, key, ?) != NULL;
}
一种可能的解决方案可能是存储值本身,但也许有特殊的常量 forundef
或 null。