Skip to content

Icingworld/WW-KVStore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WW-KVStore

这是WW系列中,关于KV存储的简易实现,使用跳表Skiplist作为底层数据结构。

一、特点

  • 将跳表设计为STL风格的容器,支持STL关联型容器相同的操作
  • 注释详细,可读性强

二、使用

1. 引入库

下载项目文件并储存至合适位置,然后在可执行文件中链接库WW::kvstore

  • 示例
target_link_libraries(YOUR_EXCUTABLE_NAME PRIVATE WW::kvstore)

2. 使用跳表

示例代码位于skiplist_test.cpp

#include <string>
#include <iostream>

#include <SkipList.h>

int main()
{
    WW::_Skiplist<std::string, std::string> _Skiplist;

    // 插入
    auto pair = _Skiplist.insert({"a", "b"});

    // 访问
    std::string value = _Skiplist.at("a");

    // 访问 & 修改
    _Skiplist["a"] = "c";

    // 删除
    _Skiplist.erase("a");

    // 迭代器
    for (auto it = _Skiplist.begin(); it != _Skiplist.end(); ++it) {
        std::cout << it->first << " " << it->second << std::endl;
    }

    return 0;
}

3. 使用KVStore

KVStore是一个简单的对跳表的封装,示例代码位于kvstore_test.cpp

#include <string>

#include <KVStore.h>

int main()
{
    WW::KVStore<std::string, std::string> store;

    // put
    store.put("name", "Alice");

    // get
    std::string name = store.get("name");

    // update
    store.update("name", "Bob");

    // remove
    store.remove("name");

    // contains
    std::cout << store.contains("name") << std::endl;

    // size
    std::cout << store.size() << std::endl;

    // empty
    std::cout << store.empty() << std::endl;

    return 0;
}

三、计划

后续将对SkipListKVStore进行优化和扩展,使得该KV存储成为相对完备的内存型数据库。

About

A KV storage based on skiplist.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy