Skip to content

Commit bf4f4f2

Browse files
committed
add CMake file; change common.h for GNU portability
1 parent a277bd2 commit bf4f4f2

File tree

9 files changed

+47
-13
lines changed

9 files changed

+47
-13
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,6 @@ FakesAssemblies/
186186
# LightSwitch generated files
187187
GeneratedArtifacts/
188188
_Pvt_Extensions/
189-
ModelManifest.xml
189+
ModelManifest.xml
190+
##vscode file
191+
.vscode/

Algon/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
project(algon)
3+
aux_source_directory(${PROJECT_SOURCE_DIR} SRC)
4+
MESSAGE(STATUS "SRC = " ${SRC})
5+
aux_source_directory( ${PROJECT_SOURCE_DIR}/dstruct DS_SRC)
6+
aux_source_directory( ${PROJECT_SOURCE_DIR}/utility UTIL_SRC)
7+
aux_source_directory( ${PROJECT_SOURCE_DIR}/algorithm ALGO_SRC)
8+
list(APPEND SRC ${DS_SRC} ${UTIL_SRC} ${ALGO_SRC} )
9+
add_compile_options(-std=c++11)
10+
SET(CXX_STANDARD 11)
11+
12+
MESSAGE("Compile flags options: " ${CMAKE_CXX_FLAGS} )
13+
MESSAGE("Sources: " ${SRC} )
14+
15+
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
16+
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
17+
add_executable(sample ${SRC})
18+
set_property(TARGET sample APPEND_STRING
19+
PROPERTY COMPILE_FLAGS "-Wall")

Algon/Example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include "dstruct/SkipList.h"
21
#include "dstruct/DisjointSet.h"
32
#include <iostream>
43
#include <string>
54
#include <stdio.h>
65
#include "utility/Exception.h"
76
#include "utility/FileIO.h"
7+
#include "dstruct/SkipList.h"
88
using namespace colinli::algon;
99
using namespace std;
1010
using namespace colinli;

Algon/algorithm/Numeric.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include <stdlib.h>
33
#include <stdint.h>
4+
#include "../common.h"
45
// #trailing zeros for n!
56
int TrailingZerosFactorial(uint32_t n);
67

Algon/common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88

99
#define NAMEOF(x) #x
1010

11+
#if defined(__GNUC__) || defined(__linux__)
12+
#include <stddef.h>
13+
#include <stdlib.h>
14+
#include <stdint.h>
15+
#include <limits.h>
16+
#include <string.h>
17+
#endif
18+
19+
1120
namespace colinli {
1221
template<class T>
1322
using uPtr = std::unique_ptr<T>;

Algon/dstruct/DisjointSet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <unordered_map>
55
#include <initializer_list>
66
#include <assert.h>
7+
#include "../common.h"
78
namespace colinli {
89
namespace algon {
910

Algon/dstruct/Heap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <functional>
77
#include <type_traits>
88
#include <cassert>
9-
9+
#include "../common.h"
1010
#define PARENT(i) ((i)>>1)
1111
#define LCHILD(i) ((i)<<1)
1212

Algon/dstruct/SkipList.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <type_traits>
44
#include <assert.h>
55
#include <cstdint>
6+
#include "../common.h"
67
#define DELETE(x) do{ \
78
delete (x);\
89
x = 0;\
@@ -21,14 +22,15 @@ struct SkipNode
2122
SkipNode(TKey k, TVal v, size_t h) :
2223
Key(k),
2324
Value(v),
24-
Height(h) {
25+
Height(h)
26+
{
2527
assert(h <= MAXHEIGHT);
2628
for (int h = MAXHEIGHT; h > 0; --h) {
2729
Forwards[h] = NULL;
2830
}
29-
}
31+
}
3032

31-
SkipNode(std::enable_if_t<std::is_default_constructible<TKey>::value, TKey>* dummy = 0):
33+
SkipNode(typename std::enable_if<std::is_default_constructible<TKey>::value, TKey>::type* dummy = 0):
3234
Key(TKey()),
3335
Value(TVal()),
3436
Height(1) {

Algon/utility/Util.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "Util.h"
22
#include <math.h>
33
#include <stdio.h>
4-
4+
#include "../common.h"
55
namespace colinli{
66
/* Return the number of digits of 'v' when converted to string in radix 10.
77
* See ll2string() for more information. */
@@ -108,23 +108,23 @@ namespace colinli{
108108

109109
int d2string(char* buf, size_t len, double value) {
110110
if (isnan(value)) {
111-
len = _snprintf(buf, len, "nan");
111+
len = snprintf(buf, len, "nan");
112112
}
113113
else if (isinf(value)) {
114114
if (value < 0)
115-
len = _snprintf(buf, len, "-inf");
115+
len = snprintf(buf, len, "-inf");
116116
else
117-
len = _snprintf(buf, len, "inf");
117+
len = snprintf(buf, len, "inf");
118118
}
119119
else if (value == 0) {
120120
/* See: http://en.wikipedia.org/wiki/Signed_zero, "Comparisons". */
121121
if (1.0 / value < 0)
122-
len = _snprintf(buf, len, "-0");
122+
len = snprintf(buf, len, "-0");
123123
else
124-
len = _snprintf(buf, len, "0");
124+
len = snprintf(buf, len, "0");
125125
}
126126
else {
127-
len = _snprintf(buf, len, "%.17g", value);
127+
len = snprintf(buf, len, "%.17g", value);
128128
}
129129

130130
return len;

0 commit comments

Comments
 (0)