Exemple #1
0
OCI_HashEntry * OCI_API OCI_HashLookup
(
    OCI_HashTable *table,
    const otext   *key,
    boolean        create
)
{
    OCI_HashEntry *e = NULL, *e1 = NULL, *e2 = NULL;
    unsigned int i;

    OCI_LIB_CALL_ENTER(OCI_HashEntry*, NULL)

    OCI_CHECK_PTR(OCI_IPC_HASHTABLE, table)
    OCI_CHECK_PTR(OCI_IPC_STRING, key)

    i = OCI_HashCompute(table, key);

    if (i < table->size)
    {
        for(e = table->items[i]; e; e = e->next)
        {
            if (ostrcasecmp(e->key, key) == 0)
            {
                break;
            }
        }

        if (!e && create)
        {
            e = (OCI_HashEntry *) OCI_MemAlloc(OCI_IPC_HASHENTRY, sizeof(*e), (size_t) 1, TRUE);

            if (e)
            {
                e->key = ostrdup(key);

                e1 = e2 = table->items[i];

                while (e1)
                {
                    e2 = e1;
                    e1 = e1->next;
                }

                if (e2)
                {
                    e2->next = e;
                }
                else
                {
                    table->items[i] = e;
                }
            }
        }
    }

    call_retval = e;
    call_status = TRUE;

    OCI_LIB_CALL_EXIT()
}
Exemple #2
0
OCI_HashEntry * OCI_API OCI_HashLookup
(
    OCI_HashTable *table,
    const mtext   *key,
    boolean        create
)
{
    OCI_HashEntry *e = NULL, *e1 = NULL, *e2 = NULL;
    unsigned int i;

    OCI_CHECK_PTR(OCI_IPC_HASHTABLE, table, NULL);
    OCI_CHECK_PTR(OCI_IPC_STRING, key, NULL);

    i = OCI_HashCompute(table, key);

    if (i < table->size)
    {
        for(e = table->items[i]; e != NULL; e = e->next)
        {
            if (mtscasecmp(e->key, key) == 0)
            {
                break;
            }
        }

        if ((e == NULL) && (create == TRUE))
        {
            e = (OCI_HashEntry *) OCI_MemAlloc(OCI_IPC_HASHENTRY, sizeof(*e), (size_t) 1, TRUE);

            if (e != NULL)
            {
                e->key = mtsdup(key);

                e1 = e2 = table->items[i];

                while (e1 != NULL)
                {
                    e2 = e1;
                    e1 = e1->next;
                }

                if (e2 != NULL)
                {
                    e2->next = e;
                }
                else
                {
                    table->items[i] = e;
                }
            }
        }
    }

    OCI_RESULT(e != NULL);

    return e;
}