File: igraph_types.h

package info (click to toggle)
igraph 1.0.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 22,444 kB
  • sloc: ansic: 155,759; cpp: 32,544; xml: 2,960; python: 411; makefile: 168; javascript: 20; sh: 9
file content (142 lines) | stat: -rw-r--r-- 5,104 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
   igraph library.
   Copyright (C) 2003-2025  The igraph development team <igraph@igraph.org>

   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 2 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 <https://www.gnu.org/licenses/>.
*/

#ifndef IGRAPH_TYPES_H
#define IGRAPH_TYPES_H

#include "igraph_decls.h"

IGRAPH_BEGIN_C_DECLS

#ifdef __cplusplus
    #define __STDC_FORMAT_MACROS   /* needed for PRId32 and PRId64 from inttypes.h on Linux */
#endif

#include "igraph_config.h"

#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>


#if !defined(IGRAPH_INTEGER_SIZE)
#  error "igraph integer size not defined; check the value of IGRAPH_INTEGER_SIZE when compiling"
#elif IGRAPH_INTEGER_SIZE == 64
typedef int64_t igraph_int_t;
typedef uint64_t igraph_uint_t;
#elif IGRAPH_INTEGER_SIZE == 32
typedef int32_t igraph_int_t;
typedef uint32_t igraph_uint_t;
#else
#  error "Invalid igraph integer size; check the value of IGRAPH_INTEGER_SIZE when compiling"
#endif

typedef igraph_int_t igraph_integer_t;

typedef double igraph_real_t;

/* IGRAPH_BOOL_TYPE is set to 'bool' by default, and it is not meant to be
 * overridden, except for the R interface where we know what we are doing.
 * See igraph_config.h for more info */
typedef IGRAPH_BOOL_TYPE igraph_bool_t;

/* printf format specifier for igraph_int_t */
#if IGRAPH_INTEGER_SIZE == 64
#  define IGRAPH_PRId PRId64
#  define IGRAPH_PRIu PRIu64
#else
#  define IGRAPH_PRId PRId32
#  define IGRAPH_PRIu PRIu32
#endif

/* maximum and minimum allowed values for igraph_int_t */
#if IGRAPH_INTEGER_SIZE == 64
#  define IGRAPH_INTEGER_MAX INT64_MAX
#  define IGRAPH_INTEGER_MIN INT64_MIN
#else
#  define IGRAPH_INTEGER_MAX INT32_MAX
#  define IGRAPH_INTEGER_MIN INT32_MIN
#endif

/* maximum and minimum allowed values for igraph_uint_t */
#if IGRAPH_INTEGER_SIZE == 64
#  define IGRAPH_UINT_MAX UINT64_MAX
#  define IGRAPH_UINT_MIN UINT64_MIN
#else
#  define IGRAPH_UINT_MAX UINT32_MAX
#  define IGRAPH_UINT_MIN UINT32_MIN
#endif


/**
 * \define IGRAPH_VCOUNT_MAX
 * \brief The maximum number of vertices supported in igraph graphs.
 *
 * The value of this constant is one less than \c IGRAPH_INTEGER_MAX .
 * When igraph is compiled in 32-bit mode, this means that you are limited
 * to 2<superscript>31</superscript> – 2 (about 2.1 billion) vertices. In
 * 64-bit mode, the limit is 2<superscript>63</superscript> – 2 so you are much
 * more likely to hit out-of-memory issues due to other reasons before reaching
 * this limit.
 */
#define IGRAPH_VCOUNT_MAX (IGRAPH_INTEGER_MAX-1)
/* The 'os' and 'is' vectors in igraph_t have vcount+1 elements,
 * thus this cannot currently be larger than IGRAPH_INTEGER_MAX-1.
 * Several functions rely on this value not exceeding IGRAPH_INTEGER_MAX-1
 * to avoid overflow.
 */

/**
 * \define IGRAPH_ECOUNT_MAX
 * \brief The maximum number of edges supported in igraph graphs.
 *
 * The value of this constant is half of \c IGRAPH_INTEGER_MAX .
 * When igraph is compiled in 32-bit mode, this means that you are limited
 * to approximately 2<superscript>30</superscript> (about 1.07 billion)
 * vertices. In 64-bit mode, the limit is approximately
 * 2<superscript>62</superscript> so you are much more likely to hit
 * out-of-memory issues due to other reasons before reaching this limit.
 */
#define IGRAPH_ECOUNT_MAX (IGRAPH_INTEGER_MAX/2)
/* The endpoints of edges are often stored in a vector twice the length
 * of the edge count, thus this cannot be larger than IGRAPH_INTEGER_MAX/2.
 * Some of the overflow checking code relies on this. */

/* Replacements for printf that print doubles in the same way on all platforms
 * (even for NaN and infinities) */
IGRAPH_EXPORT int igraph_real_printf(igraph_real_t val);
IGRAPH_EXPORT int igraph_real_fprintf(FILE *file, igraph_real_t val);
IGRAPH_EXPORT int igraph_real_printf_aligned(int width, igraph_real_t val);
IGRAPH_EXPORT int igraph_real_fprintf_aligned(FILE *file, int width, igraph_real_t val);
IGRAPH_EXPORT int igraph_real_snprintf(char *str, size_t size, igraph_real_t val);

/* Replacements for printf that print doubles in the same way on all platforms
 * (even for NaN and infinities) with the largest possible precision */
IGRAPH_EXPORT int igraph_real_printf_precise(igraph_real_t val);
IGRAPH_EXPORT int igraph_real_fprintf_precise(FILE *file, igraph_real_t val);
IGRAPH_EXPORT int igraph_real_snprintf_precise(char *str, size_t size, igraph_real_t val);

#define IGRAPH_INFINITY ((double)INFINITY)
#define IGRAPH_NAN ((double)NAN)

IGRAPH_END_C_DECLS

#endif