aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/marisa-trie/marisa/agent.cc
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2023-12-02 01:45:21 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2023-12-02 02:42:50 +0300
commit9c43d58f75cf086b744cf4fe2ae180e8f37e4a0c (patch)
tree9f88a486917d371d099cd712efd91b4c122d209d /contrib/python/marisa-trie/marisa/agent.cc
parent32fb6dda1feb24f9ab69ece5df0cb9ec238ca5e6 (diff)
downloadydb-9c43d58f75cf086b744cf4fe2ae180e8f37e4a0c.tar.gz
Intermediate changes
Diffstat (limited to 'contrib/python/marisa-trie/marisa/agent.cc')
-rw-r--r--contrib/python/marisa-trie/marisa/agent.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/contrib/python/marisa-trie/marisa/agent.cc b/contrib/python/marisa-trie/marisa/agent.cc
new file mode 100644
index 0000000000..7f7f49f1bc
--- /dev/null
+++ b/contrib/python/marisa-trie/marisa/agent.cc
@@ -0,0 +1,51 @@
+#include <new>
+
+#include "agent.h"
+#include "grimoire/trie.h"
+
+namespace marisa {
+
+Agent::Agent() : query_(), key_(), state_() {}
+
+Agent::~Agent() {}
+
+void Agent::set_query(const char *str) {
+ MARISA_THROW_IF(str == NULL, MARISA_NULL_ERROR);
+ if (state_.get() != NULL) {
+ state_->reset();
+ }
+ query_.set_str(str);
+}
+
+void Agent::set_query(const char *ptr, std::size_t length) {
+ MARISA_THROW_IF((ptr == NULL) && (length != 0), MARISA_NULL_ERROR);
+ if (state_.get() != NULL) {
+ state_->reset();
+ }
+ query_.set_str(ptr, length);
+}
+
+void Agent::set_query(std::size_t key_id) {
+ if (state_.get() != NULL) {
+ state_->reset();
+ }
+ query_.set_id(key_id);
+}
+
+void Agent::init_state() {
+ MARISA_THROW_IF(state_.get() != NULL, MARISA_STATE_ERROR);
+ state_.reset(new (std::nothrow) grimoire::State);
+ MARISA_THROW_IF(state_.get() == NULL, MARISA_MEMORY_ERROR);
+}
+
+void Agent::clear() {
+ Agent().swap(*this);
+}
+
+void Agent::swap(Agent &rhs) {
+ query_.swap(rhs.query_);
+ key_.swap(rhs.key_);
+ state_.swap(rhs.state_);
+}
+
+} // namespace marisa