-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3493601
commit 27ffdfd
Showing
9 changed files
with
183 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
## 参考资料 | ||
1. [Lucene原理](https://www.infoq.cn/article/ejeg02vroegvalw4j_ll) | ||
<div align="center"> | ||
<h1>OurSearchEngine</code></h1> | ||
|
||
<p> | ||
<strong>A simple search engine written in <code>Cpp</code></strong> | ||
</p> | ||
</div> | ||
|
||
## Requires | ||
## Features | ||
- | ||
|
||
|
||
## Architecture | ||
![Architecture](doc/pic/Arch.png) | ||
|
||
|
||
## How to use | ||
### Build | ||
```bash | ||
yay -S jsoncpp-cmake | ||
cd OurSearchEngine | ||
git submodule update --init --recursive | ||
``` | ||
cmake -B build | ||
cmake --build build | ||
``` | ||
|
||
### Use | ||
|
||
|
||
|
||
## Reference | ||
1. [Lucene](https://www.infoq.cn/article/ejeg02vroegvalw4j_ll) |
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,16 @@ | ||
#include "Queryer.h" | ||
#include <spdlog/spdlog.h> | ||
#include <benchmark/benchmark.h> | ||
using namespace SG; | ||
|
||
|
||
static void BM_Query(benchmark::State &state) { | ||
Queryer &queryer = Queryer::getInstance(); | ||
for (auto _ : state) { | ||
auto ans = queryer.get("寿命", 0, 10); | ||
benchmark::DoNotOptimize(ans); | ||
} | ||
} | ||
BENCHMARK(BM_Query); | ||
|
||
BENCHMARK_MAIN(); |
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,109 @@ | ||
#include "SkipList.h" | ||
#include <chrono> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <vector> | ||
#include <json/json.h> | ||
|
||
struct Item { | ||
int id; | ||
Item() = default; | ||
Item(int id) | ||
: id{id} {} | ||
bool operator==(const Item &t) const { | ||
return id == t.id; | ||
} | ||
bool operator<(const Item &t) const & { | ||
return id < t.id; | ||
} | ||
bool operator<(const Item &t) const && { | ||
return id < t.id; | ||
} | ||
|
||
friend std::ostream &operator<<(std::ostream &os, const Item &t) { | ||
os << '(' << t.id << ')'; | ||
return os; | ||
} | ||
|
||
static Json::Value toJson(const Item &t) { | ||
Json::Value ret; | ||
ret["id"] = t.id; | ||
return ret; | ||
} | ||
static Item fromJson(const Json::Value &src) { | ||
return {src["id"].asInt()}; | ||
} | ||
}; | ||
using SG::Core::SkipList; | ||
|
||
void test(const int &size, std::ofstream &outputFile) { | ||
srand(time(nullptr)); | ||
|
||
SkipList<Item> skipList; | ||
|
||
const int largeSize = size; | ||
|
||
// test insertion | ||
std::vector<int> insertData; | ||
srand(time(nullptr)); | ||
for (int i = 0; i < largeSize; i++) { | ||
insertData.push_back(rand() % largeSize); | ||
} | ||
|
||
auto start = std::chrono::steady_clock::now(); | ||
for (int i = 0; i < insertData.size(); i++) { | ||
skipList.insert(Item(insertData[i])); | ||
} | ||
auto end = std::chrono::steady_clock::now(); | ||
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start); | ||
outputFile << size << "," << duration.count(); | ||
|
||
// outputFile << "\n========\n" | ||
// << skipList.dump().toStyledString() << "\n========\n"; | ||
// std::cout << "=====\n"; | ||
// test deletion | ||
// std::vector<int> removeData; | ||
// srand(time(nullptr)); | ||
// for (int i = 0; i < largeSize; i++) { | ||
// removeData.push_back(rand() % largeSize); | ||
// } | ||
|
||
// start = std::chrono::steady_clock::now(); | ||
// for (int i = 0; i < removeData.size(); i++) { | ||
// skipList.remove(removeData[i]); | ||
// } | ||
// end = std::chrono::steady_clock::now(); | ||
// duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start); | ||
// outputFile << "," << duration.count(); | ||
|
||
// test search | ||
std::vector<int> searchData; | ||
for (int i = 0; i < largeSize; i++) { | ||
searchData.push_back(rand() % largeSize); | ||
} | ||
|
||
start = std::chrono::steady_clock::now(); | ||
for (int i = 0; i < searchData.size(); i++) { | ||
auto l = skipList.search(Item(searchData[i])); | ||
} | ||
end = std::chrono::steady_clock::now(); | ||
duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start); | ||
outputFile << "," << duration.count() << std::endl; | ||
|
||
// std::cout << "=====\n"; | ||
|
||
// skipList.print(); | ||
} | ||
|
||
int main() { | ||
std::ofstream outputFile("result.csv"); | ||
outputFile << "DataSize,InsertionTime,SearchTime" << std::endl; | ||
|
||
for (int i = 100; i <= 10000000; i *= 10) { | ||
test(i, outputFile); | ||
} | ||
|
||
outputFile.close(); | ||
|
||
return 0; | ||
} |