File: hashtable_i.c

package info (click to toggle)
mapserver 5.0.3-3%2Blenny7
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,556 kB
  • ctags: 12,645
  • sloc: ansic: 168,024; cs: 8,534; python: 4,618; sh: 4,213; cpp: 4,059; perl: 2,781; makefile: 787; lex: 564; java: 415; yacc: 334; tcl: 158; ruby: 53
file content (73 lines) | stat: -rw-r--r-- 2,103 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * hashtable_i.c: This file was originally based on the SWIG interface 
 *                file hashtable.i
 *
 * $Id: hashtable_i.c 3355 2004-07-26 14:12:37Z dan $
 *
 */


#include "php_mapscript.h"



/* ========================================================================
 * Include maphash header, first stating declarations to ignore
 * ======================================================================== */

#include "../../maphash.h"

/* ======================================================================== 
 * Extension methods
 * ======================================================================== */

    // New instance
    hashTableObj *hashTableObj_new() {
        return msCreateHashTable();
    }

    // Destroy instance
    void hashTableObj_destroy(hashTableObj *self) {
        msFreeHashTable(self);
    }

    // set a hash item given key and value
    int hashTableObj_set(hashTableObj *self, const char *key, const char *value) {
        if (msInsertHashTable(self, key, value) == NULL) {
	        return MS_FAILURE;
        }
        return MS_SUCCESS;
    }

    // get value from item by its key
    const char *hashTableObj_get(hashTableObj *self, const char *key) {
        char *value = NULL;
        if (!key) {
            msSetError(MS_HASHERR, "NULL key", "get");
        }
     
        value = (char *) msLookupHashTable(self, key);
        if (!value) {
            msSetError(MS_HASHERR, "Key %s does not exist", "get", key);
            return NULL;
        }
        return value;
    }

    // Remove one item from hash table
    int *hashTableObj_remove(hashTableObj *self, const char *key) {
        return msRemoveHashTable(self, key);
    }

    // Clear all items in hash table (to NULL)
    void *hashTableObj_clear(hashTableObj *self) {
        msFreeHashItems(self);
        initHashTable(self);
    }

    // Return the next key or first key if prevkey == NULL
    char *hashTableObj_nextKey(hashTableObj *self, const char *prevkey) {
        char *key;
        key = msNextKeyFromHashTable(self, prevkey);
        return key;
    }