Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Brice Videau
CCS
Commits
5b18cea8
Commit
5b18cea8
authored
Jun 11, 2020
by
Brice Videau
Browse files
Added a hash function for configurations.
parent
84613a98
Changes
6
Show whitespace changes
Inline
Side-by-side
include/ccs/base.h
View file @
5b18cea8
...
...
@@ -13,6 +13,8 @@ extern "C" {
typedef
double
ccs_float_t
;
typedef
int64_t
ccs_int_t
;
typedef
int32_t
ccs_bool_t
;
typedef
uint32_t
ccs_hash_t
;
typedef
struct
{
uint16_t
major
;
uint16_t
minor
;
...
...
include/ccs/configuration.h
View file @
5b18cea8
...
...
@@ -48,6 +48,10 @@ ccs_configuration_get_value_by_name(ccs_configuration_t configuration,
extern
ccs_error_t
ccs_configuration_check
(
ccs_configuration_t
configuration
);
extern
ccs_error_t
ccs_configuration_hash
(
ccs_configuration_t
configuration
,
ccs_hash_t
*
hash_ret
);
#ifdef __cplusplus
}
#endif
...
...
src/configuration.c
View file @
5b18cea8
#include "cconfigspace_internal.h"
#include "configuration_internal.h"
#include "datum_hash.h"
#include <string.h>
static
inline
_ccs_configuration_ops_t
*
...
...
@@ -160,3 +161,23 @@ ccs_configuration_check(ccs_configuration_t configuration) {
return
ccs_configuration_space_check_configuration
(
configuration
->
data
->
configuration_space
,
configuration
);
}
ccs_error_t
ccs_configuration_hash
(
ccs_configuration_t
configuration
,
ccs_hash_t
*
hash_ret
)
{
if
(
!
configuration
||
!
configuration
->
data
)
return
-
CCS_INVALID_OBJECT
;
if
(
!
hash_ret
)
return
-
CCS_INVALID_VALUE
;
_ccs_configuration_data_t
*
data
=
configuration
->
data
;
ccs_hash_t
h
,
ht
;
HASH_JEN
(
&
(
data
->
configuration_space
),
sizeof
(
data
->
configuration_space
),
h
);
HASH_JEN
(
&
(
data
->
num_values
),
sizeof
(
data
->
num_values
),
ht
);
h
=
_hash_combine
(
h
,
ht
);
for
(
size_t
i
=
0
;
i
<
data
->
num_values
;
i
++
)
{
ht
=
_hash_datum
(
data
->
values
+
i
);
h
=
_hash_combine
(
h
,
ht
);
}
*
hash_ret
=
h
;
return
CCS_SUCCESS
;
}
src/configuration_space.c
View file @
5b18cea8
#include "cconfigspace_internal.h"
#include "configuration_space_internal.h"
#include "configuration_internal.h"
#include "utlist.h"
static
ccs_error_t
_generate_constraints
(
ccs_configuration_space_t
configuration_space
);
...
...
src/configuration_space_internal.h
View file @
5b18cea8
#ifndef _CONFIGURATION_SPACE_INTERNAL_H
#define _CONFIGURATION_SPACE_INTERNAL_H
#include "utarray.h"
#include "context_internal.h"
#define HASH_NONFATAL_OOM 1
#include "uthash.h"
#include "utlist.h"
#include "context_internal.h"
struct
_ccs_distribution_wrapper_s
;
typedef
struct
_ccs_distribution_wrapper_s
_ccs_distribution_wrapper_t
;
...
...
src/datum_hash.h
View file @
5b18cea8
#ifndef _DATUMHASH_H
#define _DATUMHASH_H
#ifndef _DATUM
_
HASH_H
#define _DATUM
_
HASH_H
#define HASH_NONFATAL_OOM 1
#define HASH_FUNCTION(s,len,hashv) (hashv) = _hash_datum((ccs_datum_t *)(s))
...
...
@@ -51,6 +51,7 @@ static inline int _datum_cmp(ccs_datum_t *a, ccs_datum_t *b) {
else
return
strcmp
(
a
->
value
.
s
,
b
->
value
.
s
);
case
CCS_NONE
:
case
CCS_INACTIVE
:
return
0
;
break
;
default:
...
...
@@ -59,16 +60,27 @@ static inline int _datum_cmp(ccs_datum_t *a, ccs_datum_t *b) {
}
}
//from boost
static
inline
ccs_hash_t
_hash_combine
(
ccs_hash_t
h1
,
ccs_hash_t
h2
)
{
h1
^=
h2
+
0x9e3779b9
+
(
h1
<<
6
)
+
(
h1
>>
2
);
return
h1
;
}
static
inline
unsigned
_hash_datum
(
ccs_datum_t
*
d
)
{
unsigned
h
;
switch
(
d
->
type
)
{
case
CCS_STRING
:
if
(
d
->
value
.
s
)
HASH_JEN
(
d
->
value
.
s
,
strlen
(
d
->
value
.
s
),
h
);
if
(
d
->
value
.
s
)
{
unsigned
h1
,
h2
;
HASH_JEN
(
&
(
d
->
type
),
sizeof
(
d
->
type
),
h1
);
HASH_JEN
(
d
->
value
.
s
,
strlen
(
d
->
value
.
s
),
h2
);
h
=
_hash_combine
(
h1
,
h2
);
}
else
HASH_JEN
(
d
,
sizeof
(
ccs_datum_t
),
h
);
break
;
case
CCS_NONE
:
case
CCS_INACTIVE
:
HASH_JEN
(
&
(
d
->
type
),
sizeof
(
d
->
type
),
h
);
break
;
default:
...
...
@@ -84,4 +96,4 @@ struct _ccs_hash_datum_s {
typedef
struct
_ccs_hash_datum_s
_ccs_hash_datum_t
;
#endif //_DATUMHASH_H
#endif //_DATUM
_
HASH_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment