set_dict_tupleT_set_dict_tupleSetDictTupleSetDictTupleset_dict_tuple (算子)

名称

set_dict_tupleT_set_dict_tupleSetDictTupleSetDictTupleset_dict_tuple — 将键/元组对添加到字典中。

签名

set_dict_tuple( : : DictHandle, Key, Tuple : )

Herror T_set_dict_tuple(const Htuple DictHandle, const Htuple Key, const Htuple Tuple)

void SetDictTuple(const HTuple& DictHandle, const HTuple& Key, const HTuple& Tuple)

void HDict::SetDictTuple(const HTuple& Key, const HTuple& Tuple) const

void HDict::SetDictTuple(const HString& Key, const HTuple& Tuple) const

void HDict::SetDictTuple(const char* Key, const HTuple& Tuple) const

void HDict::SetDictTuple(const wchar_t* Key, const HTuple& Tuple) const   ( Windows only)

static void HOperatorSet.SetDictTuple(HTuple dictHandle, HTuple key, HTuple tuple)

void HDict.SetDictTuple(HTuple key, HTuple tuple)

void HDict.SetDictTuple(string key, HTuple tuple)

def set_dict_tuple(dict_handle: HHandle, key: MaybeSequence[Union[str, int]], tuple: Sequence[HTupleElementType]) -> None

描述

set_dict_tupleset_dict_tupleSetDictTupleSetDictTupleSetDictTupleset_dict_tuple stores a tuple associated with a key in the dictionary. The dictionary is denoted by the DictHandleDictHandleDictHandleDictHandledictHandledict_handle parameter.

TupleTupleTupleTupletupletuple including strings is copied by the operation, and can thus be immediately reused. An empty tuple is considered as a valid value that can be associated with the key. If any data (tuple or object) was already associated with given key (KeyKeyKeyKeykeykey), the old data is destroyed by set_dict_tupleset_dict_tupleSetDictTupleSetDictTupleSetDictTupleset_dict_tuple and replaced by TupleTupleTupleTupletupletuple

The KeyKeyKeyKeykeykey has to be a string or an integer. Strings are treated case sensitive.

The tuple data for the given key can be retrieved again from the dictionary using get_dict_tupleget_dict_tupleGetDictTupleGetDictTupleGetDictTupleget_dict_tuple

set_dict_tupleset_dict_tupleSetDictTupleSetDictTupleSetDictTupleset_dict_tuple allows setting the values of multiple keys with a single call. In this case, the length of TupleTupleTupleTupletupletuple must either be equal to the number of keys or 1. In the first case, TupleTupleTupleTupletupletuple is split into segments of length 1, one for each key. In the second case, if TupleTupleTupleTupletupletuple has length 1, that one value is associated with each key. If no keys are passed, the values in TupleTupleTupleTupletupletuple are ignored. The following table summarizes the possible combinations of number of keys and values, where N is an arbitrary non-negative integer:

Length of KeyKeyKeyKeykeykey Length of TupleTupleTupleTupletupletuple Effect
N 1 Value in TupleTupleTupleTupletupletuple is associated with all keys
1 N Associate TupleTupleTupleTupletupletuple with KeyKeyKeyKeykeykey
N N Associate tuples of length 1 with each passed key

注意

If the tuple contains any handles only the handle values are copied by the operation, not the resources behind those handles (no deep copy is created).

执行信息

此算子修改后续输入参数的状态:

在执行此算子时,若该参数值需在多个线程间使用,则必须对其访问进行同步。

参数

DictHandleDictHandleDictHandleDictHandledictHandledict_handle (输入控制,状态被修改)  dict HDict, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Dictionary handle.

元素数量: DictHandle == 1

KeyKeyKeyKeykeykey (输入控制)  string(-array) HTupleMaybeSequence[Union[str, int]]HTupleHtuple (string / integer) (string / int / long) (HString / Hlong) (char* / Hlong)

Key string.

TupleTupleTupleTupletupletuple (输入控制)  tuple-array HTupleSequence[HTupleElementType]HTupleHtuple (string / integer / real / handle) (string / int / long / double / HHandle) (HString / Hlong / double / HHandle) (char* / Hlong / double / handle)

Tuple value to be associated with the key.

示例(HDevelop)

create_dict (Dict)
set_dict_tuple (Dict, 'simple_integer', 27)
set_dict_tuple (Dict, 'simple_string', 'Hello world')
set_dict_tuple (Dict, 'mixed_tuple', ['The answer', 42])
set_dict_tuple (Dict, 0, 'This is zero')

结果

If the operation succeeds, set_dict_tupleset_dict_tupleSetDictTupleSetDictTupleSetDictTupleset_dict_tuple 返回 2 ( H_MSG_TRUE )。否则将抛出异常。 Possible error conditions include invalid parameters (handle or key) or resource allocation error.

可能的前趋

create_dictcreate_dictCreateDictCreateDictCreateDictcreate_dict

可能的后继

set_dict_tupleset_dict_tupleSetDictTupleSetDictTupleSetDictTupleset_dict_tuple, set_dict_objectset_dict_objectSetDictObjectSetDictObjectSetDictObjectset_dict_object

替代

set_dict_objectset_dict_objectSetDictObjectSetDictObjectSetDictObjectset_dict_object, set_dict_tuple_atset_dict_tuple_atSetDictTupleAtSetDictTupleAtSetDictTupleAtset_dict_tuple_at

另见

create_dictcreate_dictCreateDictCreateDictCreateDictcreate_dict, set_dict_tuple_atset_dict_tuple_atSetDictTupleAtSetDictTupleAtSetDictTupleAtset_dict_tuple_at, get_dict_tupleget_dict_tupleGetDictTupleGetDictTupleGetDictTupleget_dict_tuple, set_dict_objectset_dict_objectSetDictObjectSetDictObjectSetDictObjectset_dict_object, get_dict_objectget_dict_objectGetDictObjectGetDictObjectGetDictObjectget_dict_object, get_dict_paramget_dict_paramGetDictParamGetDictParamGetDictParamget_dict_param, remove_dict_keyremove_dict_keyRemoveDictKeyRemoveDictKeyRemoveDictKeyremove_dict_key

模块

基础