libcoap  4.1.2
hashkey.h
Go to the documentation of this file.
1 /*
2  * hashkey.h -- definition of hash key type and helper functions
3  *
4  * Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
5  *
6  * This file is part of the CoAP library libcoap. Please see README for terms
7  * of use.
8  */
9 
15 #ifndef _COAP_HASHKEY_H_
16 #define _COAP_HASHKEY_H_
17 
18 #include "str.h"
19 
20 typedef unsigned char coap_key_t[4];
21 
22 #ifndef coap_hash
23 
32 void coap_hash_impl(const unsigned char *s, unsigned int len, coap_key_t h);
33 
34 #define coap_hash(String,Length,Result) \
35  coap_hash_impl((String),(Length),(Result))
36 
37 /* This is used to control the pre-set hash-keys for resources. */
38 #define __COAP_DEFAULT_HASH
39 #else
40 #undef __COAP_DEFAULT_HASH
41 #endif /* coap_hash */
42 
51 #define coap_str_hash(Str,H) { \
52  assert(Str); \
53  memset((H), 0, sizeof(coap_key_t)); \
54  coap_hash((Str)->s, (Str)->length, (H)); \
55  }
56 
57 #endif /* _COAP_HASHKEY_H_ */
unsigned char coap_key_t[4]
Definition: hashkey.h:20
void coap_hash_impl(const unsigned char *s, unsigned int len, coap_key_t h)
Calculates a fast hash over the given string s of length len and stores the result into h...
Definition: hashkey.c:15