]> granicus.if.org Git - re2c/commitdiff
Moved function definitions out of header.
authorUlya Trofimovich <skvadrik@gmail.com>
Mon, 14 Mar 2016 22:38:42 +0000 (22:38 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Mon, 14 Mar 2016 22:38:42 +0000 (22:38 +0000)
re2c/Makefile.am
re2c/src/util/ord_hash_set.cc [new file with mode: 0644]
re2c/src/util/ord_hash_set.h

index 71cfb4bc79900aa772c959b103f29e15617ce876..1e73e3e36212c665903dde4f88fb3a2ace4fa1e1 100644 (file)
@@ -110,6 +110,7 @@ SRC = \
        src/parse/input.cc \
        src/parse/scanner.cc \
        src/parse/unescape.cc \
+       src/util/ord_hash_set.cc \
        src/util/s_to_n32_unsafe.cc \
        src/util/range.cc
 re2c_SOURCES = \
diff --git a/re2c/src/util/ord_hash_set.cc b/re2c/src/util/ord_hash_set.cc
new file mode 100644 (file)
index 0000000..58e30a5
--- /dev/null
@@ -0,0 +1,70 @@
+#include <stddef.h>
+
+#include "src/util/ord_hash_set.h"
+
+namespace re2c
+{
+
+ord_hash_set_t::hash_t ord_hash_set_t::hash(const void *data, size_t size)
+{
+       const uint8_t *bytes = static_cast<const uint8_t*>(data);
+       hash_t h = size; // seed
+       for (size_t i = 0; i < size; ++i)
+       {
+               h = h ^ ((h << 5) + (h >> 2) + bytes[i]);
+       }
+       return h;
+}
+
+ord_hash_set_t::elem_t* ord_hash_set_t::make_elem(
+       elem_t *next,
+       size_t index,
+       size_t size,
+       const void *data)
+{
+       elem_t *e = static_cast<elem_t*>(malloc(offsetof(elem_t, data) + size));
+       e->next = next;
+       e->index = index;
+       e->size = size;
+       memcpy(e->data, data, size);
+       return e;
+}
+
+ord_hash_set_t::ord_hash_set_t()
+       : elems()
+       , lookup()
+{}
+
+ord_hash_set_t::~ord_hash_set_t()
+{
+       std::for_each(elems.begin(), elems.end(), free);
+}
+
+size_t ord_hash_set_t::size() const
+{
+       return elems.size();
+}
+
+size_t ord_hash_set_t::insert(const void *data, size_t size)
+{
+       const hash_t h = hash(data, size);
+
+       std::map<hash_t, elem_t*>::const_iterator i = lookup.find(h);
+       if (i != lookup.end())
+       {
+               for (elem_t *e = i->second; e; e = e->next)
+               {
+                       if (e->size == size
+                               && memcmp(e->data, data, size) == 0)
+                       {
+                               return e->index;
+                       }
+               }
+       }
+
+       const size_t index = elems.size();
+       elems.push_back(lookup[h] = make_elem(lookup[h], index, size, data));
+       return index;
+}
+
+} // namespace re2c
index 9a0e73eae78284f71ea0d859b8787103906dfc57..afa1c69b596d55d7f036da4694d708b9de8884e8 100644 (file)
@@ -4,6 +4,7 @@
 #include "src/util/c99_stdint.h"
 #include <stdlib.h> // malloc, free
 #include <string.h> // memcpy
+#include <algorithm> // for_each
 #include <map>
 #include <vector>
 
@@ -41,68 +42,6 @@ public:
        template<typename data_t> size_t deref(size_t i, data_t *&data);
 };
 
-ord_hash_set_t::hash_t ord_hash_set_t::hash(const void *data, size_t size)
-{
-       const uint8_t *bytes = static_cast<const uint8_t*>(data);
-       hash_t h = size; // seed
-       for (size_t i = 0; i < size; ++i)
-       {
-               h = h ^ ((h << 5) + (h >> 2) + bytes[i]);
-       }
-       return h;
-}
-
-ord_hash_set_t::elem_t* ord_hash_set_t::make_elem(
-       elem_t *next,
-       size_t index,
-       size_t size,
-       const void *data)
-{
-       elem_t *e = static_cast<elem_t*>(malloc(offsetof(elem_t, data) + size));
-       e->next = next;
-       e->index = index;
-       e->size = size;
-       memcpy(e->data, data, size);
-       return e;
-}
-
-ord_hash_set_t::ord_hash_set_t()
-       : elems()
-       , lookup()
-{}
-
-ord_hash_set_t::~ord_hash_set_t()
-{
-       std::for_each(elems.begin(), elems.end(), free);
-}
-
-size_t ord_hash_set_t::size() const
-{
-       return elems.size();
-}
-
-size_t ord_hash_set_t::insert(const void *data, size_t size)
-{
-       const hash_t h = hash(data, size);
-
-       std::map<hash_t, elem_t*>::const_iterator i = lookup.find(h);
-       if (i != lookup.end())
-       {
-               for (elem_t *e = i->second; e; e = e->next)
-               {
-                       if (e->size == size
-                               && memcmp(e->data, data, size) == 0)
-                       {
-                               return e->index;
-                       }
-               }
-       }
-
-       const size_t index = elems.size();
-       elems.push_back(lookup[h] = make_elem(lookup[h], index, size, data));
-       return index;
-}
-
 template<typename data_t> size_t ord_hash_set_t::deref(size_t i, data_t *&data)
 {
        elem_t *e = elems[i];