maph 1.0.0 High-Performance Memory-Mapped Key-Value Database with O(1) Lookups

Loading...
Searching...
No Matches
Functions | Variables
maph_cli.cpp File Reference

Command-line interface for maph database. More...

`#include "maph.hpp"`
`#include <iostream>`
`#include <fstream>`
`#include <chrono>`
`#include <cstring>`
`#include <iomanip>`
`#include <thread>`
Include dependency graph for maph_cli.cpp:

Go to the source code of this file.

## Functions
void | usage ()
| Display comprehensive usage information.
int | main (int argc, char *argv[])
| Main entry point for maph CLI.

## Variables
constexpr int | EXIT_SUCCESS_CODE = 0
constexpr int | EXIT_ERROR_CODE = 1
constexpr int | EXIT_INVALID_ARGS = 2
constexpr int | EXIT_FILE_ERROR = 3
constexpr int | EXIT_DATABASE_FULL = 4

## Detailed Description

Command-line interface for maph database.

Provides a comprehensive CLI for interacting with maph databases including:

- Database creation and management
- Key-value operations (get, set, remove)
- Batch operations for high-throughput scenarios
- Performance benchmarking tools
- Bulk data import/export

Usage: maph <command> [arguments] [options]

Author
  Maph Development Team

Version
  1.0.0

Definition in file maph_cli.cpp.

## Function Documentation

## ◆ main()

int main | ( | int | argc,
|  | char * | argv[]
| ) |  |

Main entry point for maph CLI.

Parses command-line arguments and dispatches to appropriate command handler. Supports various operations on maph databases including CRUD operations, batch processing, and performance benchmarking.

Parameters

  argc | Argument count
  argv | Argument vector

Returns
  Exit code (0 for success, non-zero for various error conditions)

CREATE command - Create a new database file

Usage: maph create <file> <slots>

Creates a new memory-mapped database with the specified number of slots. The file size will be approximately slots * 512 bytes + header.

SET command - Store a key-value pair

Usage: maph set <file> <key>

Stores or updates a value in the database. Value must be <= 496 bytes. Returns error if database is full or value is too large.

GET command - Retrieve a value by key

Usage: maph get <file> <key>

Retrieves the value associated with the key. Prints the value to stdout if found, "null" if not found. Uses read-only mode for better performance and safety.

REMOVE command - Delete a key-value pair

Usage: maph remove <file> <key>

Removes the specified key from the database. The slot is marked as empty and can be reused.

STATS command - Display database statistics

Usage: maph stats <file>

Shows detailed statistics including slot usage, memory consumption, load factor, and generation counter. Useful for monitoring database health.

BENCH command - Run single-threaded performance benchmark

Usage: maph bench <file>

Performs sequential write and read operations to measure throughput. Writes 100,000 key-value pairs then reads them back. Reports operations per second for both writes and reads.

BENCH_PARALLEL command - Run multi-threaded performance benchmark

Usage: maph bench_parallel <file> [threads]

Performs parallel write and read operations using multiple threads. If thread count is not specified, uses hardware concurrency. Demonstrates scalability and parallel throughput capabilities.

LOAD_BULK command - Import data from JSONL file

Usage: maph load_bulk <file> <jsonl> [–threads <n>]

Loads key-value pairs from a JSONL file using parallel processing. Each line should contain {"input": key, "output": value}. Supports custom thread count for optimal performance.

MGET command - Get multiple keys in batch

Usage: maph mget <file> <key1> [key2] [key3] ...

Retrieves multiple keys efficiently using prefetching. Prints each found key-value pair to stdout. More efficient than multiple individual get operations.

MSET command - Set multiple key-value pairs in batch

Usage: maph mset <file> <key1> <value1> [key2] [value2] ...

Sets multiple key-value pairs efficiently in a single operation. Arguments must come in pairs (key followed by value). Reports how many pairs were successfully stored.

Definition at line 56 of file maph_cli.cpp.

## ◆ usage()

void usage | ( |  | ) |

Display comprehensive usage information.

Prints all available commands, options, and examples to stderr. Called when invalid arguments are provided or –help is requested.

Definition at line 41 of file maph_cli.cpp.

## Variable Documentation

## ◆ EXIT_DATABASE_FULL

constexpr int EXIT_DATABASE_FULL = 4
| constexpr

Definition at line 33 of file maph_cli.cpp.

## ◆ EXIT_ERROR_CODE

constexpr int EXIT_ERROR_CODE = 1
| constexpr

Definition at line 30 of file maph_cli.cpp.

## ◆ EXIT_FILE_ERROR

constexpr int EXIT_FILE_ERROR = 3
| constexpr

Definition at line 32 of file maph_cli.cpp.

## ◆ EXIT_INVALID_ARGS

constexpr int EXIT_INVALID_ARGS = 2
| constexpr

Definition at line 31 of file maph_cli.cpp.

## ◆ EXIT_SUCCESS_CODE

constexpr int EXIT_SUCCESS_CODE = 0
| constexpr

Definition at line 29 of file maph_cli.cpp.