GitHub PullRequestReviewCommentEvent at 2014-01-16 10:18:06
Repository: hyrise
Actor: grundprinzip
Payload: {"comment":{"url":"https://api.github.com/repos/hyrise/hyrise/pulls/comments/8926922","id":8926922,"diff_hunk":"@@ -193,5 +180,215 @@ class OrderPreservingDictionaryIterator : public BaseIterator<T> {\n \n };\n \n+\n+/// String Dictionary Specialization\n+class OrderPreservingDictionaryIteratorString : public BaseIterator<std::string> {\n+\n+  using dictionary_type =  OrderPreservingDictionary<std::string>;\n+  using base_type = OrderPreservingDictionaryIteratorString;\n+\n+  dictionary_type *_data = nullptr;\n+  size_t _index = 0;\n+\n+  std::string _value;\n+\n+public:\n+  explicit OrderPreservingDictionaryIteratorString(dictionary_type *values);\n+\n+  OrderPreservingDictionaryIteratorString(dictionary_type *values, size_t index);\n+\n+  void increment();\n+\n+  bool equal(const std::shared_ptr<BaseIterator<std::string>>& other) const;\n+\n+  std::string dereference();\n+\n+  value_id_t getValueId() const;\n+\n+};\n+\n+\n+\n+\n+template <>\n+class OrderPreservingDictionary<std::string> : public BaseDictionary<std::string> {\n+\n+  using char_trait = std::char_traits<char>;\n+  using char_ptr_t = char_trait::char_type*;\n+  using str_size_t = unsigned;\n+\n+  // Offset into the char memory\n+  std::vector<char_trait::off_type> _offset;\n+  \n+  char_ptr_t _data = nullptr;\n+  char_ptr_t _end = nullptr;\n+  char_ptr_t _endOfStorage = nullptr;\n+\n+  // Basic offset for storing the size o the string\n+  constexpr static size_t _basicOffset = sizeof(str_size_t);\n+\n+  /*\n+   * Returns a const char pointer to the string and shift by the size\n+   * of the string\n+   */\n+  char_ptr_t get_c_offset(size_t offset) const {\n+    return _data + offset + _basicOffset;\n+  }\n+\n+  /* \n+   * Returns the size of the string, based on the offset\n+   */\n+  str_size_t get_strlen(size_t offset) const {\n+    return *reinterpret_cast<str_size_t*>(_data + offset);\n+  }\n+\n+\n+  void reserve_raw(size_t bytes) {\n+    auto oldEnd = _end - _data;\n+    _data = static_cast<char_ptr_t>(realloc(_data, bytes * sizeof(char_trait::char_type)));\n+    _end = _data + oldEnd;\n+    _endOfStorage = _data + bytes;\n+  }\n+\n+  size_t allocated() const {\n+    return _endOfStorage - _data;\n+  }\n+\n+\n+public:\n+\n+  OrderPreservingDictionary() {\n+  }\n+\n+  OrderPreservingDictionary(const OrderPreservingDictionary& other) = delete;\n+  \n+  OrderPreservingDictionary& operator= (OrderPreservingDictionary& other) = delete;\n+  \n+  explicit OrderPreservingDictionary(size_t size) {\n+  }\n+\n+  virtual ~OrderPreservingDictionary() {\n+    if (_data != nullptr)\n+      free(_data);\n+  }\n+\n+  void shrink() {\n+  }\n+\n+  /**\n+   * Return value of given value id\n+   *\n+   * @param value the value id\n+   * @return value of the value id\n+   */\n+  value_id_t addValue(std::string value) {\n+#ifdef EXPENSIVE_ASSERTIONS\n+    if ((_offset.size() > 0) && (value <= get_s(_offset.size() - 1)))\n+      throw std::runtime_error(\"Can't insert value smaller or equal to last value\");\n+#endif\n+    if ((_end + value.size() + _basicOffset) > _endOfStorage) {\n+      // Allocate at least one object plus its size\n+      reserve_raw(value.size() + _basicOffset + (allocated() * 2) );\n+    }\n+\n+    // Copy the data\n+    str_size_t s = value.size();\n+    memcpy(_end, &s, _basicOffset);\n+    memcpy(_end + _basicOffset, value.c_str(), s);\n+    _offset.emplace_back(_end - _data);\n+    _end = _end + s + _basicOffset;\n+    return _offset.size() - 1;\n+  }\n+\n+\n+  /*\n+   * String transformation\n+   */\n+  std::string get_s(size_t index) const {\n+    const auto off = _offset[index];\n+    return std::string(get_c_offset(off), get_strlen(off));\n+  }\n+  \n+  /**\n+   * Return value of given value id\n+   *\n+   * @param value the value id\n+   * @return value of the value\n+   */\n+  std::string getValueForValueId(value_id_t value_id) {\n+#ifdef EXPENSIVE_ASSERTIONS\n+    if (value_id >= _offset.size())\n+      throw std::out_of_range(\"Trying to access value_id larger than available values\");\n+#endif\n+    return std::move(get_s(value_id));","path":"src/lib/storage/OrderPreservingDictionary.h","position":191,"original_position":191,"commit_id":"9ca7ab92fab6f99a9f390258a14935cc4dffb849","original_commit_id":"9ca7ab92fab6f99a9f390258a14935cc4dffb849","user":{"login":"grundprinzip","id":3421,"avatar_url":"https://gravatar.com/avatar/9036fdd3def5eae9979c02b3c99665df?d=https%3A%2F%2Fidenticons.github.com%2Fe846fb8a4f365ca8e84393d4f34e1b07.png&r=x","gravatar_id":"9036fdd3def5eae9979c02b3c99665df","url":"https://api.github.com/users/grundprinzip","html_url":"https://github.com/grundprinzip","followers_url":"https://api.github.com/users/grundprinzip/followers","following_url":"https://api.github.com/users/grundprinzip/following{/other_user}","gists_url":"https://api.github.com/users/grundprinzip/gists{/gist_id}","starred_url":"https://api.github.com/users/grundprinzip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grundprinzip/subscriptions","organizations_url":"https://api.github.com/users/grundprinzip/orgs","repos_url":"https://api.github.com/users/grundprinzip/repos","events_url":"https://api.github.com/users/grundprinzip/events{/privacy}","received_events_url":"https://api.github.com/users/grundprinzip/received_events","type":"User","site_admin":false},"body":"You mean only for RVO?","created_at":"2014-01-16T10:18:06Z","updated_at":"2014-01-16T10:18:06Z","html_url":"https://github.com/hyrise/hyrise/pull/298#discussion_r8926922","pull_request_url":"https://api.github.com/repos/hyrise/hyrise/pulls/298","_links":{"self":{"href":"https://api.github.com/repos/hyrise/hyrise/pulls/comments/8926922"},"html":{"href":"https://github.com/hyrise/hyrise/pull/298#discussion_r8926922"},"pull_request":{"href":"https://api.github.com/repos/hyrise/hyrise/pulls/298"}}}}