data_structures
src
types
type_char.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* type_char.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2020/07/16 22:27:52 by unite #+# #+# */
10
/* Updated: 2020/09/04 22:54:36 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
types.h
"
15
16
void
*type_char_copy(
const
void
*c)
17
{
18
char
*copy;
19
20
if
(!c || !(copy = malloc(
sizeof
(
char
))))
21
return
(NULL);
22
*copy = *(
char
*)c;
23
return
(copy);
24
}
25
26
int
type_char_cmp(
const
void
*c1,
const
void
*c2)
27
{
28
if
(!c1 && !c2)
29
return
(0);
30
if
(!c1)
31
return
(-1);
32
if
(!c2)
33
return
(-1);
34
if
(*(
char
*)c1 < *(
char
*)c2)
35
return
(-1);
36
if
(*(
char
*)c1 > *(
char
*)c2)
37
return
(1);
38
return
(0);
39
}
40
41
size_t
type_char_hash(
const
void
*c,
size_t
M)
42
{
43
return
(*(
size_t
*)c % M);
44
}
45
46
static
const
t_type
g_type_char_struct = {
47
.
name
=
"char"
,
48
.copy = &type_char_copy,
49
.del = &free,
50
.cmp = &type_char_cmp,
51
.hash = &type_char_hash,
52
};
53
54
const
t_type
*
g_type_char
= &g_type_char_struct;
55
s_type::name
char * name
The name of a datatype as a string.
Definition:
types.h:49
types.h
g_type_char
const t_type * g_type_char
A representation of the char data type.
Definition:
type_char.c:54
s_type
A full representation of a data type, used to achieve polymorphism in the implementation of data stru...
Definition:
types.h:47
Generated by
1.8.16