diff options
| author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-17 19:27:15 +0000 | 
|---|---|---|
| committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-17 19:27:15 +0000 | 
| commit | ad1cadf3512f3dd789151983e5c93af411f929db (patch) | |
| tree | d6d25d562617d9bec7b13286cf413ed8f7567275 /omegalib/omega_lib/src | |
| parent | cfafd2ffcad803e7bb02b60c085eafd73f28f87a (diff) | |
| download | chill-ad1cadf3512f3dd789151983e5c93af411f929db.tar.gz chill-ad1cadf3512f3dd789151983e5c93af411f929db.tar.bz2 chill-ad1cadf3512f3dd789151983e5c93af411f929db.zip  | |
restructure
Diffstat (limited to 'omegalib/omega_lib/src')
| -rw-r--r-- | omegalib/omega_lib/src/basic/ConstString.cc | 134 | ||||
| -rw-r--r-- | omegalib/omega_lib/src/basic/Link.cc | 41 | ||||
| -rwxr-xr-x | omegalib/omega_lib/src/hull_simple.cc | 2 | ||||
| -rw-r--r-- | omegalib/omega_lib/src/omega_core/oc_exp_kill.cc | 2 | ||||
| -rw-r--r-- | omegalib/omega_lib/src/omega_core/oc_quick_kill.cc | 2 | ||||
| -rw-r--r-- | omegalib/omega_lib/src/omega_core/oc_simple.cc | 2 | 
6 files changed, 179 insertions, 4 deletions
diff --git a/omegalib/omega_lib/src/basic/ConstString.cc b/omegalib/omega_lib/src/basic/ConstString.cc new file mode 100644 index 0000000..7d2ec1e --- /dev/null +++ b/omegalib/omega_lib/src/basic/ConstString.cc @@ -0,0 +1,134 @@ +#include <basic/ConstString.h> +#include <stdlib.h> +#include <stdio.h> +#include <assert.h> +#include <string> +#include <string.h> + +/* static const int CS_HashTable_Size = 1000; */ +/* static ConstStringRep *hashTable[CS_HashTable_Size] = {0}; */ + +namespace omega { + +const int CS_HashTable_Size = 1000; +class CS_HashTable { +public: +  ConstStringRep *p[CS_HashTable_Size]; +  CS_HashTable(); +  ~CS_HashTable(); +}; + +namespace { +  CS_HashTable hashTable; +} + +CS_HashTable::CS_HashTable() { +    for (int i = 0; i < CS_HashTable_Size; i++) +      p[i] = NULL; +  } + +CS_HashTable::~CS_HashTable() { +  for (int i = 0; i < CS_HashTable_Size; i++) { +    ConstStringRep *t = p[i]; +    while (t != NULL) { +      ConstStringRep *tt = t->nextInBucket; +      delete []t->name; +      delete t; +      t = tt; +    } +  }     +} + +Const_String::Const_String() { +  rep = 0; +} + +void Const_String::buildRep(const char* t) { +  int hash = 0; +  const char *s = t; +  while (*s != '\0')  +    hash = hash*33 + *s++; +  int hashBucket = hash % CS_HashTable_Size; +  if (hashBucket < 0) hashBucket += CS_HashTable_Size; +  assert(0 <= hashBucket && hashBucket < CS_HashTable_Size); +  ConstStringRep **q = &(hashTable.p[hashBucket]); +  ConstStringRep *p = *q; +  while (p != 0) { +    if (strcmp(p->name,t) == 0) break; +    q = &p->nextInBucket;   +    p = *q; +  } +  if (p!= 0) rep = p; +  else { +    rep = new ConstStringRep(t); +    *q = rep; +  } +} + +Const_String::Const_String(const char * t) { +  buildRep(t); +} + +Const_String::Const_String(const std::string &s) { +  buildRep(s.c_str()); +} + +Const_String::operator const char*() const { +  if (!rep) return 0; +  return rep->name; +} + +Const_String::operator std::string() const { +  if (!rep) return std::string(""); +  return std::string(rep->name); +} + +int Const_String::operator++(int) { +  return rep->count++; +} + +int Const_String::operator++() { +  return ++rep->count; +} + +int Const_String:: operator--(int) { +  return rep->count--; +} + +int Const_String:: operator--() { +  return --rep->count; +} + +int operator ==(const Const_String &x, const Const_String &y) { +  return x.rep == y.rep; +} + +int operator !=(const Const_String &x, const Const_String &y) { +  return x.rep != y.rep; +} + +int operator <(const Const_String &x, const Const_String &y) { +  return (strcmp(x.rep->name,y.rep->name) < 0); +} + +int operator >(const Const_String &x, const Const_String &y) { +  return (strcmp(x.rep->name,y.rep->name) > 0); +} + +Const_String:: operator int() const { +  return rep != 0; +} + +int Const_String::null() const { +  return rep == 0; +} + +ConstStringRep:: ConstStringRep(const char *t) { +  count = 0; +  nextInBucket = 0; +  char *s = new char[1+strlen(t)]; +  strcpy(s,t); +  name = s; +} + +} // namespace diff --git a/omegalib/omega_lib/src/basic/Link.cc b/omegalib/omega_lib/src/basic/Link.cc new file mode 100644 index 0000000..50b9441 --- /dev/null +++ b/omegalib/omega_lib/src/basic/Link.cc @@ -0,0 +1,41 @@ +#include <basic/Link.h> + +namespace omega { + +#if ListElementFreeList +  static List_Element<void*> *_kludgy_List_Element_free_list_pointer; +// we rely on the fact that that is initialized to 0 before any +// constructor-based initialization that could call List_Element::new. + +  void *kludgy_List_Element_new(size_t size) +    { +    void *mem; +    if (size == sizeof(List_Element<void*>) && +	_kludgy_List_Element_free_list_pointer) +	{ +	List_Element<void*> *it = _kludgy_List_Element_free_list_pointer; +	_kludgy_List_Element_free_list_pointer = it->tail; +	mem = it; +	} +    else +	mem = ::operator new(size); + +    return mem; +    } + +  void  kludgy_List_Element_delete(void *ptr, size_t size) +    { +    if (ptr) +	if (size == sizeof(List_Element<void*>)) +	    { +	    List_Element<void*> *it = (List_Element<void*> *) ptr; +	    it->tail = _kludgy_List_Element_free_list_pointer; +	    _kludgy_List_Element_free_list_pointer = it; +	    } +	else +	    ::operator delete(ptr); +    } + +#endif + +} // namespace diff --git a/omegalib/omega_lib/src/hull_simple.cc b/omegalib/omega_lib/src/hull_simple.cc index 93d8ad3..62dcb26 100755 --- a/omegalib/omega_lib/src/hull_simple.cc +++ b/omegalib/omega_lib/src/hull_simple.cc @@ -14,7 +14,7 @@  #include <assert.h>  #include <omega.h> -#include <basic/boolset.h> +#include <basic/BoolSet.h>  #include <vector>  #include <list>  #include <set> diff --git a/omegalib/omega_lib/src/omega_core/oc_exp_kill.cc b/omegalib/omega_lib/src/omega_core/oc_exp_kill.cc index bf3ba19..fdb2718 100644 --- a/omegalib/omega_lib/src/omega_core/oc_exp_kill.cc +++ b/omegalib/omega_lib/src/omega_core/oc_exp_kill.cc @@ -13,7 +13,7 @@  *****************************************************************************/  #include <omega/omega_core/oc_i.h> -#include <basic/boolset.h> +#include <basic/BoolSet.h>  #include <vector>  namespace omega { diff --git a/omegalib/omega_lib/src/omega_core/oc_quick_kill.cc b/omegalib/omega_lib/src/omega_core/oc_quick_kill.cc index e49aee7..1b988d4 100644 --- a/omegalib/omega_lib/src/omega_core/oc_quick_kill.cc +++ b/omegalib/omega_lib/src/omega_core/oc_quick_kill.cc @@ -15,7 +15,7 @@  #include <omega/omega_core/oc_i.h>  #include <vector>  #include <algorithm> -#include <basic/boolset.h> +#include <basic/BoolSet.h>  namespace omega { diff --git a/omegalib/omega_lib/src/omega_core/oc_simple.cc b/omegalib/omega_lib/src/omega_core/oc_simple.cc index ebbf407..0e492db 100644 --- a/omegalib/omega_lib/src/omega_core/oc_simple.cc +++ b/omegalib/omega_lib/src/omega_core/oc_simple.cc @@ -15,7 +15,7 @@  *****************************************************************************/  #include <omega/omega_core/oc_i.h> -#include <basic/boolset.h> +#include <basic/BoolSet.h>  #include <algorithm>  #include <vector>  | 
