/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to libssts/utils.c

  • Committer: Gustav Hartvigsson
  • Date: 2017-01-24 20:55:19 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20170124205519-gtr18o3dwbunrrnx
* Fixed the tests in the CMake file
* Made doxygen output static declarations.
* Started work on SApplication
* Played with BaseN.c
  * Now it is a lil' bit better
* Spilt defs.h
  * Added types.h
    * Started work on the full typesystem.
      (Still needs testing)
  * Added primes.[c,h]
    * Contains some static array with primes.
      ("Good" primes, and all primes up to 5 000.
    * And helper functions related to Primes (Needs Tests).
* fixed s_dynamic_array_dump_array.
  (The old version did not make much sense)
* removed some functions from DymanicArray.c
* fixed compiler warnings in Mainloop.c
* removed s_map_(de)serialize_json functions.
* Made s_thread_status_get_name be less prone to error
  (This due to the C11 standard not specifing what these
   values should be)
* fixed s_thread_run
* fixed s_threa_stop

  TODO:
* Write tests for the s_prime_* functions
* Write tests for the s_type_* functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
309
309
  return NULL;
310
310
}
311
311
 
 
312
/*
 
313
 * See: http://www.programmingsimplified.com/c/source-code/c-program-binary-search
 
314
 */
 
315
#define _INTERNAL_MAKE_BIN_SEARCH_FUNC(T) \
 
316
sboolean \
 
317
s_binary_search_##T ( T list[], size_t f, size_t l, T n) {\
 
318
  size_t first = f;\
 
319
  size_t last = l;\
 
320
  size_t middle = (first + last)/2;\
 
321
  \
 
322
  while (first <= last) {\
 
323
    if (SPrimeListLong[middle] < n) {\
 
324
     first = middle + 1;\
 
325
    } else if (list[middle == n]) {\
 
326
      return TRUE;\
 
327
    } else {\
 
328
      last = middle - 1;\
 
329
    }\
 
330
    middle = (first + last) / 2;\
 
331
  }\
 
332
  return FALSE;\
 
333
}
 
334
 
 
335
_INTERNAL_MAKE_BIN_SEARCH_FUNC(sbyte)
 
336
 
 
337
_INTERNAL_MAKE_BIN_SEARCH_FUNC(subyte)
 
338
 
 
339
_INTERNAL_MAKE_BIN_SEARCH_FUNC(sshort)
 
340
 
 
341
_INTERNAL_MAKE_BIN_SEARCH_FUNC(sushort)
 
342
 
 
343
_INTERNAL_MAKE_BIN_SEARCH_FUNC(sint)
 
344
 
 
345
_INTERNAL_MAKE_BIN_SEARCH_FUNC(suint)
 
346
 
 
347
_INTERNAL_MAKE_BIN_SEARCH_FUNC(slong)
 
348
 
 
349
_INTERNAL_MAKE_BIN_SEARCH_FUNC(sulong)
 
350
 
 
351
_INTERNAL_MAKE_BIN_SEARCH_FUNC(sfloat)
 
352
 
 
353
_INTERNAL_MAKE_BIN_SEARCH_FUNC(sdouble)
 
354
 
 
355
_INTERNAL_MAKE_BIN_SEARCH_FUNC(squadruple)
 
356
 
 
357
 
 
358
/* ************************************************************************** 
 
359
 * Signal handlers
 
360
 * ************************************************************************** */
 
361
void
 
362
s_sig_segfault (int code) {
 
363
  if (code == SIGSEGV) {
 
364
    print_backtrace();
 
365
  }
 
366
}
 
367
 
312
368