X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fmap.qc;h=fc7012cc0b43e16cfe0c76d29f78885167c83d07;hb=3fbc261b483be2c73f5514c3a938696b6679efc3;hp=aee2a363765d50bb7f52629b6af65d161f4c10ac;hpb=6603ee5ff104719d3d4b9dad7ae4bf66f46706e5;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/map.qc b/qcsrc/lib/map.qc index aee2a3637..fc7012cc0 100644 --- a/qcsrc/lib/map.qc +++ b/qcsrc/lib/map.qc @@ -1,6 +1,8 @@ #ifndef MAP_H #define MAP_H +#include "int.qh" + // Databases (hash tables) const int DB_BUCKETS = 8192; void db_save(int db, string filename) @@ -17,10 +19,13 @@ void db_save(int db, string filename) fclose(fh); } +typedef int HashMap; + int db_create() { return buf_create(); } +#define HM_NEW(this) (this = db_create()) void db_put(int db, string key, string value); @@ -75,12 +80,14 @@ void db_close(int db) { buf_del(db); } +#define HM_DELETE(this) db_close(this) string db_get(int db, string key) { int h = crc16(false, key) % DB_BUCKETS; return uri_unescape(infoget(bufstr_get(db, h), key)); } +#define HM_gets(this, k) db_get(this, k) #define db_remove(db, key) db_put(db, key, "") @@ -89,6 +96,7 @@ void db_put(int db, string key, string value) int h = crc16(false, key) % DB_BUCKETS; bufstr_set(db, h, infoadd(bufstr_get(db, h), key, uri_escape(value))); } +#define HM_sets(this, key, val) db_put(this, key, val) void db_test() {