• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "lang_id/common/fel/workspace.h"
18 
19 #include <atomic>
20 #include <string>
21 
22 namespace libtextclassifier3 {
23 namespace mobile {
24 
25 // static
GetFreshTypeId()26 int GetFreshTypeId() {
27   // Static local below is initialized the first time this method is run.
28   static std::atomic<int> counter(0);
29   return counter++;
30 }
31 
DebugString() const32 string WorkspaceRegistry::DebugString() const {
33   string str;
34   for (auto &it : workspace_names_) {
35     const string &type_name = workspace_types_.at(it.first);
36     for (size_t index = 0; index < it.second.size(); ++index) {
37       const string &workspace_name = it.second[index];
38       str.append("\n  ");
39       str.append(type_name);
40       str.append(" :: ");
41       str.append(workspace_name);
42     }
43   }
44   return str;
45 }
46 
VectorIntWorkspace(int size)47 VectorIntWorkspace::VectorIntWorkspace(int size) : elements_(size) {}
48 
VectorIntWorkspace(int size,int value)49 VectorIntWorkspace::VectorIntWorkspace(int size, int value)
50     : elements_(size, value) {}
51 
VectorIntWorkspace(const std::vector<int> & elements)52 VectorIntWorkspace::VectorIntWorkspace(const std::vector<int> &elements)
53     : elements_(elements) {}
54 
TypeName()55 string VectorIntWorkspace::TypeName() { return "Vector"; }
56 
57 }  // namespace mobile
58 }  // namespace nlp_saft
59