-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What problem does this PR solve? Boost fulltext insertion performance. Issue link:#358 ### Type of change - [x] Refactoring - [x] Performance Improvement
- Loading branch information
1 parent
42d7742
commit 58b3217
Showing
26 changed files
with
331 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright(C) 2023 InfiniFlow, Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
module; | ||
|
||
export module vector_with_lock; | ||
import stl; | ||
|
||
namespace infinity { | ||
|
||
export template <typename ValueType> | ||
class VectorWithLock { | ||
private: | ||
std::shared_mutex mutex_; | ||
Vector<ValueType> vec_; | ||
|
||
public: | ||
VectorWithLock() = default; | ||
VectorWithLock(SizeT count) : vec_(count) {} | ||
VectorWithLock(SizeT count, const ValueType &value) : vec_(count, value) {} | ||
|
||
~VectorWithLock() = default; | ||
|
||
void Resize(SizeT new_size) { | ||
std::unique_lock<std::shared_mutex> lock(mutex_); | ||
vec_.resize(new_size); | ||
} | ||
|
||
ValueType Get(SizeT i) { | ||
std::shared_lock<std::shared_mutex> lock(mutex_); | ||
return vec_[i]; | ||
} | ||
|
||
ValueType Sum() { | ||
ValueType sum = 0; | ||
std::shared_lock<std::shared_mutex> lock(mutex_); | ||
for (SizeT i = 0; i < vec_.size(); ++i) | ||
sum += vec_[i]; | ||
return sum; | ||
} | ||
|
||
void Set(SizeT i, const ValueType &value) { | ||
std::unique_lock<std::shared_mutex> lock(mutex_); | ||
vec_[i] = value; | ||
} | ||
|
||
void SetBatch(SizeT begin_idx, const Vector<ValueType> &values) { | ||
SizeT required_size = begin_idx + values.size(); | ||
std::unique_lock<std::shared_mutex> lock(mutex_); | ||
if (vec_.size() < required_size) | ||
vec_.resize(required_size); | ||
for (SizeT i = 0; i < values.size(); ++i) | ||
vec_[begin_idx + i] = values[i]; | ||
} | ||
|
||
Vector<ValueType> &UnsafeVec() { return vec_; } | ||
|
||
void Clear() { | ||
std::unique_lock<std::shared_mutex> lock(mutex_); | ||
vec_.clear(); | ||
} | ||
}; | ||
} // namespace infinity |
Oops, something went wrong.