Skip to content

Commit 4608758

Browse files
committed
Missing files in last commit.
1 parent a7e62e8 commit 4608758

File tree

6 files changed

+54
-3
lines changed

6 files changed

+54
-3
lines changed

include/2darray.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ namespace alg
6666
inline T& operator() (int row, int col) { return this->m_data[row*NC + col]; }
6767
const inline T& operator() (int row, int col) const { return this->m_data[row*NC + col]; }
6868

69+
inline T* operator[] (int row) { return &(m_data[row * NC]); }
70+
inline const T* operator[] (int row) const { return &(m_data[row * NC]); }
71+
6972
/**
7073
* clear the array by a given value
7174
*/

include/double_linked_list.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,14 @@ static inline void list_splice_init(struct list_head *list,
197197
* @type: the type of the struct this is embedded in.
198198
* @member: the name of the list_struct within the struct.
199199
*/
200+
#ifndef _MSC_VER
200201
#define list_entry(ptr, type, member) \
201202
(reinterpret_cast<type *>((char *)(ptr)-(char *)(&(reinterpret_cast<type *>(1)->member))+1))
203+
#else
204+
#define list_entry(ptr, ptrtype, member) \
205+
(reinterpret_cast<ptrtype>((char *)(ptr)-(char *)(&(reinterpret_cast<ptrtype>(1)->member))+1))
206+
#endif
207+
202208

203209
/**
204210
* list_for_each - iterate over a list
@@ -233,23 +239,44 @@ static inline void list_splice_init(struct list_head *list,
233239
* @head: the head for your list.
234240
* @member: the name of the list_struct within the struct.
235241
*/
242+
#ifndef _MSC_VER
236243
#define list_for_each_entry(pos, head, member) \
237244
for (pos = list_entry((head)->next, typeof(*pos), member); \
238245
&pos->member != (head); \
239246
pos = list_entry(pos->member.next, typeof(*pos), member))
240-
247+
#else
248+
#define list_for_each_entry(pos, head, member) \
249+
for (pos = list_entry((head)->next, typeof(pos), member); \
250+
&pos->member != (head); \
251+
pos = list_entry(pos->member.next, typeof(pos), member))
252+
#endif
241253
/**
242254
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
243255
* @pos: the type * to use as a loop counter.
244256
* @n: another type * to use as temporary storage
245257
* @head: the head for your list.
246258
* @member: the name of the list_struct within the struct.
247259
*/
260+
#ifndef _MSC_VER
248261
#define list_for_each_entry_safe(pos, n, head, member) \
249262
for (pos = list_entry((head)->next, typeof(*pos), member), \
250263
n = list_entry(pos->member.next, typeof(*pos), member); \
251264
&pos->member != (head); \
252265
pos = n, n = list_entry(n->member.next, typeof(*n), member))
253266

267+
#else
268+
269+
template<class T>
270+
struct TypeofHelper
271+
{
272+
typedef T Type;
273+
};
274+
275+
#define list_for_each_entry_safe(pos, n, head, member) \
276+
for (pos = list_entry((head)->next, TypeofHelper<typeof(pos)>::Type, member), \
277+
n = list_entry(pos->member.next, TypeofHelper<typeof(pos)>::Type, member); \
278+
&(pos->member) != (head); \
279+
pos = n, n = list_entry(n->member.next, TypeofHelper<typeof(n)>::Type, member))
280+
#endif
254281

255282
#endif

include/hash_multi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ namespace alg
4343
return hash;
4444
}
4545

46+
#ifdef _MSC_VER
47+
#define log2(x) (log(x) / log(2))
48+
#endif
49+
4650
/**
4751
* init a hash table with size specified.
4852
*/

include/word_seg.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#include "hash_table.h"
2929
#include "queue.h"
3030

31+
#ifdef ALG_VLA_NOT_SUPPORTED
32+
#include "2darray.h"
33+
#endif//ALG_VLA_NOT_SUPPORTED
34+
3135
namespace alg
3236
{
3337
/**
@@ -199,14 +203,27 @@ namespace alg
199203
int pos = 0;
200204
int len = strlen(str);
201205

206+
#ifdef ALG_VLA_NOT_SUPPORTED
207+
alg::Array2D<double> V(len, 4);
208+
uint32_t CH;
209+
210+
// record the path
211+
alg::Array2D<> path(4, len+1);
212+
alg::Array2D<> newpath(4, len+1);
213+
214+
path.clear(0);
215+
newpath.clear(0);
216+
#else
202217
double V[len][4];
203218
uint32_t CH;
204219

205220
// record the path
206221
char path[4][len+1];
207222
char newpath[4][len+1];
223+
208224
memset(path,0, sizeof(path));
209225
memset(newpath,0, sizeof(newpath));
226+
#endif
210227

211228
// Initialize base case. the first observation.
212229
int i;

src/lcs_demo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ do { \
1515
int main(void)
1616
{
1717
using namespace alg;
18-
int MAXN = 10;
18+
const int MAXN = 10;
1919
int X[MAXN];
2020
int Y[MAXN];
2121

src/perfect_hash_demo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
int main(void)
2222
{
2323
using namespace alg;
24-
int MAXELEMENT = 100;
24+
const int MAXELEMENT = 100;
2525

2626
uint32_t keys[MAXELEMENT];
2727
uint32_t values[MAXELEMENT];

0 commit comments

Comments
 (0)