taskrambler  v0.1.8
Web server and task management solution.
hash/delete.c
Go to the documentation of this file.
1 /**
2  * \file
3  *
4  * \author Georg Hopp
5  *
6  * \copyright
7  * Copyright © 2012 Georg Hopp
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include <sys/types.h>
24 
25 #include "asset.h"
26 #include "hash.h"
27 #include "utils/hash.h"
28 
29 static
30 inline
31 int
32 hashDeleteComp(const void * a, const void * b)
33 {
34  unsigned long hash_a = hashableGetHash((void*)a);
35 
36  if (hash_a < *(const unsigned long*)b) {
37  return -1;
38  }
39 
40  if (hash_a > *(const unsigned long*)b) {
41  return 1;
42  }
43 
44  return 0;
45 }
46 
47 void *
48 hashDelete(Hash this, const char * search, size_t nsearch)
49 {
50  unsigned long hash = sdbm((const unsigned char *)search, nsearch);
51  void * found = NULL;
52 
53  found = treeDelete(&(this->root), &hash, hashDeleteComp);
54 
55  return found;
56 }
57 
58 void *
59 hashDeleteByVal(Hash this, unsigned long hash)
60 {
61  void * found = treeDelete(&(this->root), &hash, hashDeleteComp);
62 
63  return found;
64 }
65 
66 // vim: set ts=4 sw=4:
void * hashDeleteByVal(Hash this, unsigned long hash)
Definition: hash/delete.c:59
unsigned long sdbm(const unsigned char *, size_t)
Definition: utils/hash.c:45
unsigned long hashableGetHash(void *)
Definition: hashable.c:36
static int hashDeleteComp(const void *a, const void *b)
Definition: hash/delete.c:32
void * hashDelete(Hash this, const char *search, size_t nsearch)
Definition: hash/delete.c:48
void * treeDelete(Tree *, const void *, TreeComp)
Definition: tree/delete.c:31