diff options
author | Lance <Lance@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-05-22 12:15:49 +0000 |
---|---|---|
committer | Lance <Lance@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-05-22 12:15:49 +0000 |
commit | de7175c5bc24b6e8f3b87540ae93f40a75df2df2 (patch) | |
tree | 4517d2916188504401ad86868e641edb35b40617 /src/common/db.c | |
parent | d0565d61b91c9784717e756c72b871099175408b (diff) | |
download | hercules-de7175c5bc24b6e8f3b87540ae93f40a75df2df2.tar.gz hercules-de7175c5bc24b6e8f3b87540ae93f40a75df2df2.tar.bz2 hercules-de7175c5bc24b6e8f3b87540ae93f40a75df2df2.tar.xz hercules-de7175c5bc24b6e8f3b87540ae93f40a75df2df2.zip |
* WARNING: New scripting system contains memory leak
TODO: Free all scripts using script_free_code() instead of old methods.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@6690 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/db.c')
-rw-r--r-- | src/common/db.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/common/db.c b/src/common/db.c index 65abecea7..ebb5b9a30 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -2342,3 +2342,107 @@ void db_final(void) #endif /* DB_ENABLE_STATS */
}
+// Link DB System - jAthena
+void linkdb_insert( struct linkdb_node** head, void *key, void* data) {
+ struct linkdb_node *node;
+ if( head == NULL ) return ;
+ node = aMalloc( sizeof(struct linkdb_node) );
+ if( *head == NULL ) {
+ // first node
+ *head = node;
+ node->prev = NULL;
+ node->next = NULL;
+ } else {
+ // link nodes
+ node->next = *head;
+ node->prev = (*head)->prev;
+ (*head)->prev = node;
+ (*head) = node;
+ }
+ node->key = key;
+ node->data = data;
+}
+
+void* linkdb_search( struct linkdb_node** head, void *key) {
+ int n = 0;
+ struct linkdb_node *node;
+ if( head == NULL ) return NULL;
+ node = *head;
+ while( node ) {
+ if( node->key == key ) {
+ if( node->prev && n > 5 ) {
+ // 処理効率改善の為にheadに移動させる
+ if(node->prev) node->prev->next = node->next;
+ if(node->next) node->next->prev = node->prev;
+ node->next = *head;
+ node->prev = (*head)->prev;
+ (*head)->prev = node;
+ (*head) = node;
+ }
+ return node->data;
+ }
+ node = node->next;
+ n++;
+ }
+ return NULL;
+}
+
+void* linkdb_erase( struct linkdb_node** head, void *key) {
+ struct linkdb_node *node;
+ if( head == NULL ) return NULL;
+ node = *head;
+ while( node ) {
+ if( node->key == key ) {
+ void *data = node->data;
+ if( node->prev == NULL )
+ *head = node->next;
+ else
+ node->prev->next = node->next;
+ if( node->next )
+ node->next->prev = node->prev;
+ aFree( node );
+ return data;
+ }
+ node = node->next;
+ }
+ return NULL;
+}
+
+void linkdb_replace( struct linkdb_node** head, void *key, void *data ) {
+ int n = 0;
+ struct linkdb_node *node;
+ if( head == NULL ) return ;
+ node = *head;
+ while( node ) {
+ if( node->key == key ) {
+ if( node->prev && n > 5 ) {
+ // 処理効率改善の為にheadに移動させる
+ if(node->prev) node->prev->next = node->next;
+ if(node->next) node->next->prev = node->prev;
+ node->next = *head;
+ node->prev = (*head)->prev;
+ (*head)->prev = node;
+ (*head) = node;
+ }
+ node->data = data;
+ return ;
+ }
+ node = node->next;
+ n++;
+ }
+ // 見つからないので挿入
+ linkdb_insert( head, key, data );
+}
+
+void linkdb_final( struct linkdb_node** head ) {
+ struct linkdb_node *node, *node2;
+ if( head == NULL ) return ;
+ node = *head;
+ while( node ) {
+ node2 = node->next;
+ aFree( node );
+ node = node2;
+ }
+ *head = NULL;
+}
+
|