1
// Copyright 2010, Google Inc.
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
8
// * Redistributions of source code must retain the above copyright
9
// notice, this list of conditions and the following disclaimer.
10
// * Redistributions in binary form must reproduce the above
11
// copyright notice, this list of conditions and the following disclaimer
12
// in the documentation and/or other materials provided with the
14
// * Neither the name of Google Inc. nor the names of its
15
// contributors may be used to endorse or promote products derived from
16
// this software without specific prior written permission.
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
#include "converter/converter_data.h"
33
#include "base/base.h"
34
#include "converter/key_corrector.h"
38
ConverterData::ConverterData(): bos_node_(NULL),
40
key_corrector_(new KeyCorrector),
42
max_nodes_size_(8192) {}
44
ConverterData::~ConverterData() {}
46
Node *ConverterData::NewNode() {
47
Node *node = node_freelist_.Alloc();
52
Node **ConverterData::begin_nodes_list() {
53
return &begin_nodes_list_[0];
56
Node **ConverterData::end_nodes_list() {
57
return &end_nodes_list_[0];
60
const KeyCorrector &ConverterData::key_corrector() const {
61
return *(key_corrector_.get());
64
void ConverterData::set_key(const string &key,
65
KeyCorrector::InputMode mode) {
67
const size_t size = key.size();
68
begin_nodes_list_.resize(size + 4);
69
end_nodes_list_.resize(size + 4);
70
fill(begin_nodes_list_.begin(), begin_nodes_list_.end(),
71
static_cast<Node *>(NULL));
72
fill(end_nodes_list_.begin(), end_nodes_list_.end(),
73
static_cast<Node *>(NULL));
74
key_corrector_->CorrectKey(key, mode);
77
const string &ConverterData::key() const {
81
bool ConverterData::has_lattice() const {
82
return !begin_nodes_list_.empty();
85
void ConverterData::clear_lattice() {
87
begin_nodes_list_.clear();
88
end_nodes_list_.clear();
89
node_freelist_.Free();