File: hashtable_i.c

package info (click to toggle)
mapserver 4.10.0-5.1%2Betch4
  • links: PTS
  • area: main
  • in suites: etch
  • size: 12,264 kB
  • ctags: 15,165
  • sloc: ansic: 164,837; sh: 6,141; python: 5,770; java: 5,169; perl: 2,388; cpp: 1,603; makefile: 735; lex: 507; yacc: 317; tcl: 158; cs: 85; ruby: 53
file content (73 lines) | stat: -rw-r--r-- 2,107 bytes parent folder | download | duplicates (3)
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,v 1.1 2004/07/26 14:12:37 dan Exp $
 *
 */


#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;
    }