X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fmap.qh;h=d89dc2b6457ed51d632307c7d41c550646f61567;hb=8ed3353314a7a50059c3856005a0f933cfa806b7;hp=55da4d63f0caab22ec1c305a02ad0ca85822e116;hpb=af71335a8e418edc55126a63aa65afd9353f413c;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/map.qh b/qcsrc/lib/map.qh index 55da4d63f..d89dc2b64 100644 --- a/qcsrc/lib/map.qh +++ b/qcsrc/lib/map.qh @@ -4,6 +4,7 @@ // Databases (hash tables) const int DB_BUCKETS = 8192; +ERASEABLE void db_save(int db, string filename) { int fh = fopen(filename, FILE_WRITE); @@ -20,14 +21,17 @@ void db_save(int db, string filename) USING(HashMap, int); +ERASEABLE int db_create() { return buf_create(); } #define HM_NEW(this) (this = db_create()) +ERASEABLE void db_put(int db, string key, string value); +ERASEABLE int db_load(string filename) { int db = buf_create(); @@ -61,10 +65,11 @@ int db_load(string filename) return db; } +ERASEABLE void db_dump(int db, string filename) { int fh = fopen(filename, FILE_WRITE); - if (fh < 0) LOG_FATALF("Can't dump DB to %s"); + if (fh < 0) LOG_FATALF("Can't dump DB to %s", filename); fputs(fh, "0\n"); for (int i = 0, n = buf_getsize(db); i < n; ++i) { @@ -75,12 +80,14 @@ void db_dump(int db, string filename) fclose(fh); } +ERASEABLE void db_close(int db) { buf_del(db); } #define HM_DELETE(this) db_close(this) +ERASEABLE string db_get(int db, string key) { int h = crc16(false, key) % DB_BUCKETS; @@ -90,6 +97,7 @@ string db_get(int db, string key) #define db_remove(db, key) db_put(db, key, "") +ERASEABLE void db_put(int db, string key, string value) { int h = crc16(false, key) % DB_BUCKETS; @@ -97,6 +105,7 @@ void db_put(int db, string key, string value) } #define HM_sets(this, key, val) db_put(this, key, val) +/* void db_test() { LOG_INFO("LOAD...\n"); @@ -110,3 +119,4 @@ void db_test() db_close(db); LOG_INFO("CLOSED.\n"); } +*/