Example #1
0
static void
idict_add(struct idict_t *dict, int key, int val) {
        int i = idict_find(dict, key);

        if (i == -1) {
                /* no key found, append it as a new one */
                int *ivec = NULL;

                if (dict->size >= dict->alloc) {
                        idict_resize(dict, dict->size + IDICT_DEFAULT_STEP);
                }

                IVEC_NEW(ivec, 0);
                IVEC_KEY(ivec) = key;
                IVEC_APPEND(ivec, val);

                dict->pvec[ dict->size ] = ivec;
                dict->size ++;
                dict->vnum ++;
        }
        else {
                /* find a key, append to the specific vector */
                IVEC_APPEND(dict->pvec[i], val);
        }
}
Example #2
0
/* <dict> <int> .setmaxlength - */
static int
zsetmaxlength(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    os_ptr op1 = op - 1;
    uint new_size;
    int code;

    check_type(*op1, t_dictionary);
    if (i_ctx_p->in_superexec == 0)
	check_dict_write(*op1);
    check_type(*op, t_integer);
    if (op->value.intval < 0)
	return_error(e_rangecheck);
    new_size = (uint) op->value.intval;
    if (dict_length(op - 1) > new_size)
	return_error(e_dictfull);
    code = idict_resize(op - 1, new_size);
    if (code >= 0)
	pop(2);
    return code;
}