taskrambler  0.1.9
Web server and task management solution.
hash/value.c File Reference
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "class.h"
#include "utils/hash.h"
#include "utils/memory.h"
#include "commons.h"
#include "hash/value.h"
#include "hash/interface/hashable.h"
+ Include dependency graph for hash/value.c:

Go to the source code of this file.

Functions

static int hashValueCtor (void *_this, va_list *params)
 
static void hashValueDtor (void *_this)
 
static unsigned long hashValueGetHash (void *_this)
 
static void hashValueHandleDouble (void *_this, void *_double)
 
 INIT_IFACE (Class, hashValueCtor, hashValueDtor, NULL)
 
 INIT_IFACE (Hashable, hashValueGetHash, hashValueHandleDouble)
 
 CREATE_CLASS (HashValue, NULL, IFACE(Class), IFACE(Hashable))
 

Detailed Description

Author
Georg Hopp

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file hash/value.c.

Function Documentation

CREATE_CLASS ( HashValue  ,
NULL  ,
IFACE(Class)  ,
IFACE(Hashable)   
)
static int hashValueCtor ( void *  _this,
va_list *  params 
)
static

Definition at line 38 of file hash/value.c.

References memMalloc(), and sdbm().

39 {
40  HashValue this = _this;
41  char * key = va_arg(* params, char*);
42  void * value;
43 
44  this->nkey = va_arg(* params, size_t);
45  value = va_arg(* params, void*);
46  this->nvalue = va_arg(* params, size_t);
47 
48  this->key = memMalloc(this->nkey + 1);
49  this->key[this->nkey] = 0;
50  memcpy(this->key, key, this->nkey);
51 
52  this->hash = sdbm((unsigned char *)this->key, this->nkey);
53 
54  if (NULL != value) {
55  this->value = memMalloc(this->nvalue + 1);
56  ((char*)this->value)[this->nvalue] = 0;
57  memcpy(this->value, value, this->nvalue);
58  }
59 
60  return 0;
61 }
unsigned long sdbm(const unsigned char *, size_t)
Definition: utils/hash.c:45
void * memMalloc(size_t)
Definition: memory.c:783

+ Here is the call graph for this function:

static void hashValueDtor ( void *  _this)
static

Definition at line 65 of file hash/value.c.

References MEM_FREE.

66 {
67  HashValue this = _this;
68 
69  MEM_FREE(this->key);
70  MEM_FREE(this->value);
71 }
#define MEM_FREE(seg)
Definition: memory.h:28
static unsigned long hashValueGetHash ( void *  _this)
static

Definition at line 75 of file hash/value.c.

76 {
77  HashValue this = _this;
78 
79  return this->hash;
80 }
static void hashValueHandleDouble ( void *  _this,
void *  _double 
)
static

here we swap the internal data of both objects, effectively overwriting the old entry. We need not to free anything here as _double will be deleted afterwards anyway (

See also
hash/add.c).

Definition at line 84 of file hash/value.c.

85 {
86  HashValue this = _this;
87  HashValue doub = _double;
88  void * tmp_value;
89  size_t tmp_nvalue;
90 
91  /**
92  * here we swap the internal data of both objects,
93  * effectively overwriting the old entry. We need not
94  * to free anything here as _double will be deleted
95  * afterwards anyway (\see hash/add.c).
96  */
97  tmp_value = this->value;
98  this->value = doub->value;
99  doub->value = tmp_value;
100 
101  tmp_nvalue = this->nvalue;
102  this->nvalue = doub->nvalue;
103  doub->nvalue = tmp_nvalue;
104 }
INIT_IFACE ( Class  ,
hashValueCtor  ,
hashValueDtor  ,
NULL   
)
INIT_IFACE ( Hashable  ,
hashValueGetHash  ,
hashValueHandleDouble   
)