1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5 //
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
9
10 #include "util/file_checksum_helper.h"
11
12 namespace ROCKSDB_NAMESPACE {
13
reset()14 void FileChecksumListImpl::reset() { checksum_map_.clear(); }
15
size() const16 size_t FileChecksumListImpl::size() const { return checksum_map_.size(); }
17
GetAllFileChecksums(std::vector<uint64_t> * file_numbers,std::vector<std::string> * checksums,std::vector<std::string> * checksum_func_names)18 Status FileChecksumListImpl::GetAllFileChecksums(
19 std::vector<uint64_t>* file_numbers, std::vector<std::string>* checksums,
20 std::vector<std::string>* checksum_func_names) {
21 if (file_numbers == nullptr || checksums == nullptr ||
22 checksum_func_names == nullptr) {
23 return Status::InvalidArgument("Pointer has not been initiated");
24 }
25
26 for (auto i : checksum_map_) {
27 file_numbers->push_back(i.first);
28 checksums->push_back(i.second.first);
29 checksum_func_names->push_back(i.second.second);
30 }
31 return Status::OK();
32 }
33
SearchOneFileChecksum(uint64_t file_number,std::string * checksum,std::string * checksum_func_name)34 Status FileChecksumListImpl::SearchOneFileChecksum(
35 uint64_t file_number, std::string* checksum,
36 std::string* checksum_func_name) {
37 if (checksum == nullptr || checksum_func_name == nullptr) {
38 return Status::InvalidArgument("Pointer has not been initiated");
39 }
40
41 auto it = checksum_map_.find(file_number);
42 if (it == checksum_map_.end()) {
43 return Status::NotFound();
44 } else {
45 *checksum = it->second.first;
46 *checksum_func_name = it->second.second;
47 }
48 return Status::OK();
49 }
50
InsertOneFileChecksum(uint64_t file_number,const std::string & checksum,const std::string & checksum_func_name)51 Status FileChecksumListImpl::InsertOneFileChecksum(
52 uint64_t file_number, const std::string& checksum,
53 const std::string& checksum_func_name) {
54 auto it = checksum_map_.find(file_number);
55 if (it == checksum_map_.end()) {
56 checksum_map_.insert(std::make_pair(
57 file_number, std::make_pair(checksum, checksum_func_name)));
58 } else {
59 it->second.first = checksum;
60 it->second.second = checksum_func_name;
61 }
62 return Status::OK();
63 }
64
RemoveOneFileChecksum(uint64_t file_number)65 Status FileChecksumListImpl::RemoveOneFileChecksum(uint64_t file_number) {
66 auto it = checksum_map_.find(file_number);
67 if (it == checksum_map_.end()) {
68 return Status::NotFound();
69 } else {
70 checksum_map_.erase(it);
71 }
72 return Status::OK();
73 }
74
NewFileChecksumList()75 FileChecksumList* NewFileChecksumList() {
76 FileChecksumListImpl* checksum_list = new FileChecksumListImpl();
77 return checksum_list;
78 }
79
CreateFileChecksumFuncCrc32c()80 FileChecksumFunc* CreateFileChecksumFuncCrc32c() {
81 FileChecksumFunc* file_checksum_crc32c = new FileChecksumFuncCrc32c();
82 return file_checksum_crc32c;
83 }
84
85 } // namespace ROCKSDB_NAMESPACE
86