Skip to content

Commit 5ba8e40

Browse files
committed
surface_matching: fix infinite loop, whitespace issues
1 parent 11c90ea commit 5ba8e40

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

modules/surface_matching/src/ppf_helpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Mat loadPLYSimple(const char* fileName, int withNormals)
121121
{
122122
float* data = cloud.ptr<float>(i);
123123
int col = 0;
124-
for (; col < withNormals ? 6 : 3; ++col)
124+
for (; col < (withNormals ? 6 : 3); ++col)
125125
{
126126
ifs >> data[col];
127127
}

modules/surface_matching/src/t_hash_int.cpp

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ size_t hash( unsigned int a)
6464
hashtable_int *hashtableCreate(size_t size, size_t (*hashfunc)(unsigned int))
6565
{
6666
hashtable_int *hashtbl;
67-
67+
6868
if (size < 16)
6969
{
7070
size = 16;
@@ -73,25 +73,25 @@ hashtable_int *hashtableCreate(size_t size, size_t (*hashfunc)(unsigned int))
7373
{
7474
size = (size_t)next_power_of_two((unsigned int)size);
7575
}
76-
77-
hashtbl=(hashtable_int*)malloc(sizeof(hashtable_int));
76+
77+
hashtbl=(hashtable_int*)malloc(sizeof(hashtable_int));
7878
if (!hashtbl)
7979
return NULL;
80-
81-
hashtbl->nodes=(hashnode_i**)calloc(size, sizeof(struct hashnode_i*));
80+
81+
hashtbl->nodes=(hashnode_i**)calloc(size, sizeof(struct hashnode_i*));
8282
if (!hashtbl->nodes)
8383
{
8484
free(hashtbl);
8585
return NULL;
8686
}
87-
87+
8888
hashtbl->size=size;
89-
89+
9090
if (hashfunc)
9191
hashtbl->hashfunc=hashfunc;
9292
else
9393
hashtbl->hashfunc=hash;
94-
94+
9595
return hashtbl;
9696
}
9797

@@ -100,7 +100,7 @@ void hashtableDestroy(hashtable_int *hashtbl)
100100
{
101101
size_t n;
102102
struct hashnode_i *node, *oldnode;
103-
103+
104104
for (n=0; n<hashtbl->size; ++n)
105105
{
106106
node=hashtbl->nodes[n];
@@ -120,10 +120,10 @@ int hashtableInsert(hashtable_int *hashtbl, KeyType key, void *data)
120120
{
121121
struct hashnode_i *node;
122122
size_t hash=hashtbl->hashfunc(key)%hashtbl->size;
123-
124-
123+
124+
125125
/* fpruintf(stderr, "hashtbl_insert() key=%s, hash=%d, data=%s\n", key, hash, (char*)data);*/
126-
126+
127127
node=hashtbl->nodes[hash];
128128
while (node)
129129
{
@@ -134,29 +134,29 @@ int hashtableInsert(hashtable_int *hashtbl, KeyType key, void *data)
134134
}
135135
node=node->next;
136136
}
137-
138-
139-
node=(hashnode_i*)malloc(sizeof(struct hashnode_i));
137+
138+
139+
node=(hashnode_i*)malloc(sizeof(struct hashnode_i));
140140
if (!node)
141141
return -1;
142142
node->key=key;
143-
143+
144144
node->data=data;
145145
node->next=hashtbl->nodes[hash];
146146
hashtbl->nodes[hash]=node;
147-
148-
147+
148+
149149
return 0;
150150
}
151151

152152
int hashtableInsertHashed(hashtable_int *hashtbl, KeyType key, void *data)
153153
{
154154
struct hashnode_i *node;
155155
size_t hash = key % hashtbl->size;
156-
157-
156+
157+
158158
/* fpruintf(stderr, "hashtbl_insert() key=%s, hash=%d, data=%s\n", key, hash, (char*)data);*/
159-
159+
160160
node=hashtbl->nodes[hash];
161161
while (node)
162162
{
@@ -167,18 +167,18 @@ int hashtableInsertHashed(hashtable_int *hashtbl, KeyType key, void *data)
167167
}
168168
node=node->next;
169169
}
170-
171-
node=(hashnode_i*)malloc(sizeof(struct hashnode_i));
170+
171+
node=(hashnode_i*)malloc(sizeof(struct hashnode_i));
172172
if (!node)
173173
return -1;
174-
174+
175175
node->key=key;
176-
176+
177177
node->data=data;
178178
node->next=hashtbl->nodes[hash];
179179
hashtbl->nodes[hash]=node;
180-
181-
180+
181+
182182
return 0;
183183
}
184184

@@ -187,7 +187,7 @@ int hashtableRemove(hashtable_int *hashtbl, KeyType key)
187187
{
188188
struct hashnode_i *node, *prevnode=NULL;
189189
size_t hash=hashtbl->hashfunc(key)%hashtbl->size;
190-
190+
191191
node=hashtbl->nodes[hash];
192192
while (node)
193193
{
@@ -203,7 +203,7 @@ int hashtableRemove(hashtable_int *hashtbl, KeyType key)
203203
prevnode=node;
204204
node=node->next;
205205
}
206-
206+
207207
return -1;
208208
}
209209

@@ -212,24 +212,24 @@ void *hashtableGet(hashtable_int *hashtbl, KeyType key)
212212
{
213213
struct hashnode_i *node;
214214
size_t hash=hashtbl->hashfunc(key)%hashtbl->size;
215-
215+
216216
/* fprintf(stderr, "hashtbl_get() key=%s, hash=%d\n", key, hash);*/
217-
217+
218218
node=hashtbl->nodes[hash];
219219
while (node)
220220
{
221221
if (node->key==key)
222222
return node->data;
223223
node=node->next;
224224
}
225-
225+
226226
return NULL;
227227
}
228228

229229
hashnode_i* hashtableGetBucketHashed(hashtable_int *hashtbl, KeyType key)
230230
{
231231
size_t hash = key % hashtbl->size;
232-
232+
233233
return hashtbl->nodes[hash];
234234
}
235235

@@ -238,29 +238,29 @@ int hashtableResize(hashtable_int *hashtbl, size_t size)
238238
hashtable_int newtbl;
239239
size_t n;
240240
struct hashnode_i *node,*next;
241-
241+
242242
newtbl.size=size;
243243
newtbl.hashfunc=hashtbl->hashfunc;
244-
245-
newtbl.nodes=(hashnode_i**)calloc(size, sizeof(struct hashnode_i*));
244+
245+
newtbl.nodes=(hashnode_i**)calloc(size, sizeof(struct hashnode_i*));
246246
if (!newtbl.nodes)
247247
return -1;
248-
248+
249249
for (n=0; n<hashtbl->size; ++n)
250250
{
251251
for (node=hashtbl->nodes[n]; node; node=next)
252252
{
253253
next = node->next;
254254
hashtableInsert(&newtbl, node->key, node->data);
255255
hashtableRemove(hashtbl, node->key);
256-
256+
257257
}
258258
}
259-
259+
260260
free(hashtbl->nodes);
261261
hashtbl->size=newtbl.size;
262262
hashtbl->nodes=newtbl.nodes;
263-
263+
264264
return 0;
265265
}
266266

@@ -270,24 +270,24 @@ int hashtableWrite(const hashtable_int * hashtbl, const size_t dataSize, FILE* f
270270
size_t hashMagic=T_HASH_MAGIC;
271271
size_t n=hashtbl->size;
272272
size_t i;
273-
273+
274274
fwrite(&hashMagic, sizeof(size_t),1, f);
275275
fwrite(&n, sizeof(size_t),1, f);
276276
fwrite(&dataSize, sizeof(size_t),1, f);
277-
277+
278278
for (i=0; i<hashtbl->size; i++)
279279
{
280280
struct hashnode_i* node=hashtbl->nodes[i];
281281
size_t noEl=0;
282-
282+
283283
while (node)
284284
{
285285
noEl++;
286286
node=node->next;
287287
}
288-
288+
289289
fwrite(&noEl, sizeof(size_t),1, f);
290-
290+
291291
node=hashtbl->nodes[i];
292292
while (node)
293293
{
@@ -296,7 +296,7 @@ int hashtableWrite(const hashtable_int * hashtbl, const size_t dataSize, FILE* f
296296
node=node->next;
297297
}
298298
}
299-
299+
300300
return 1;
301301
}
302302

@@ -305,13 +305,13 @@ void hashtablePrint(hashtable_int *hashtbl)
305305
{
306306
size_t n;
307307
struct hashnode_i *node,*next;
308-
308+
309309
for (n=0; n<hashtbl->size; ++n)
310310
{
311311
for (node=hashtbl->nodes[n]; node; node=next)
312312
{
313313
next = node->next;
314-
std::cout<<"Key : "<<node->key<<", Data : "<<node->data<<std::endl;
314+
std::cout<<"Key : "<<node->key<<", Data : "<<node->data<<std::endl;
315315
}
316316
}
317317
}
@@ -321,28 +321,28 @@ hashtable_int *hashtableRead(FILE* f)
321321
size_t hashMagic = 0;
322322
size_t n = 0, status;
323323
hashtable_int *hashtbl = 0;
324-
324+
325325
status = fread(&hashMagic, sizeof(size_t),1, f);
326326
if (status && hashMagic==T_HASH_MAGIC)
327327
{
328328
size_t i;
329329
size_t dataSize;
330330
status = fread(&n, sizeof(size_t),1, f);
331331
status = fread(&dataSize, sizeof(size_t),1, f);
332-
332+
333333
hashtbl=hashtableCreate(n, hash);
334-
334+
335335
for (i=0; i<hashtbl->size; i++)
336336
{
337337
size_t j=0;
338338
status = fread(&n, sizeof(size_t),1, f);
339-
339+
340340
for (j=0; j<n; j++)
341341
{
342342
int key=0;
343343
void* data=0;
344344
status = fread(&key, sizeof(KeyType), 1, f);
345-
345+
346346
if (dataSize>sizeof(void*))
347347
{
348348
data=malloc(dataSize);
@@ -355,15 +355,15 @@ hashtable_int *hashtableRead(FILE* f)
355355
}
356356
else
357357
status = fread(&data, dataSize, 1, f);
358-
358+
359359
hashtableInsert(hashtbl, key, data);
360360
//free(key);
361361
}
362362
}
363363
}
364364
else
365365
return 0;
366-
366+
367367
return hashtbl;
368368
}
369369

0 commit comments

Comments
 (0)