#include "components/omnibox/browser/on_device_head_model.h"
#include <algorithm>
#include <cstring>
#include <fstream>
#include <list>
#include <memory>
#include "base/containers/heap_array.h"
#include "base/containers/span.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
namespace {
const int kRootNodeOffset = …;
struct MatchCandidate { … };
CandidateQueue;
class OnDeviceModelParams { … };
uint32_t ConvertCharSpanToInt(base::span<const char> chars) { … }
bool OpenModelFileStream(OnDeviceModelParams* params,
const std::string& model_filename,
const uint32_t start_address) { … }
void MaybeCloseModelFileStream(OnDeviceModelParams* params) { … }
bool ReadNext(OnDeviceModelParams* params, base::span<char> buf) { … }
uint32_t ReadNextNumBytesAsInt(OnDeviceModelParams* params,
uint32_t num_bytes,
bool* is_successful) { … }
bool AreSizesValid(OnDeviceModelParams* params) { … }
void InsertCandidateToQueue(const MatchCandidate& candidate,
CandidateQueue* leaf_queue,
CandidateQueue* non_leaf_queue) { … }
uint32_t GetMinScoreFromQueues(OnDeviceModelParams* params,
const CandidateQueue& queue_1,
const CandidateQueue& queue_2) { … }
uint32_t ReadMaxScoreAsRoot(OnDeviceModelParams* params,
uint32_t address,
MatchCandidate* leaf_candidate,
bool* is_successful) { … }
bool ReadNextChild(OnDeviceModelParams* params, MatchCandidate* candidate) { … }
std::vector<MatchCandidate> ReadTreeNode(OnDeviceModelParams* params,
const MatchCandidate& current) { … }
bool FindStartNode(OnDeviceModelParams* params,
const std::string& prefix,
MatchCandidate* start_match) { … }
std::vector<std::pair<std::string, uint32_t>> DoSearch(
OnDeviceModelParams* params,
const MatchCandidate& start_match) { … }
}
std::unique_ptr<OnDeviceModelParams> OnDeviceModelParams::Create(
const std::string& model_filename,
const uint32_t max_num_matches_to_return) { … }
OnDeviceModelParams::~OnDeviceModelParams() { … }
std::vector<std::pair<std::string, uint32_t>>
OnDeviceHeadModel::GetSuggestionsForPrefix(const std::string& model_filename,
uint32_t max_num_matches_to_return,
const std::string& prefix) { … }