Skip to content

Commit f09a1a4

Browse files
committed
Commit
1 parent c535290 commit f09a1a4

File tree

2 files changed

+56
-116
lines changed

2 files changed

+56
-116
lines changed

README.md

Lines changed: 56 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,94 @@
1+
# KeyArray 🚀
12

2-
# 🔑 KeyArray
3+
![KeyArray](https://img.shields.io/badge/KeyArray-High%20Performance%20C%2B%2B%20Data%20Structure-blue)
34

4-
**KeyArray** is a high-performance data structure that combines the speed of array-based access with the flexibility of dynamic key management.
5-
It is designed to guarantee **O(1)** time complexity (worst-case) for insert, remove, access, and key existence operations – even without hashing or rebalancing.
5+
Welcome to **KeyArray**, a high-performance C++ data structure designed for fast key-based access. With guaranteed O(1) operations, dynamic resizing, and a memory-efficient design, KeyArray is perfect for applications that require quick access to data.
66

7-
---
7+
## Table of Contents
88

9-
## ⚡ Why KeyArray?
9+
- [Features](#features)
10+
- [Installation](#installation)
11+
- [Usage](#usage)
12+
- [Contributing](#contributing)
13+
- [License](#license)
14+
- [Releases](#releases)
15+
- [Contact](#contact)
1016

11-
Unlike hash maps, vectors, or linked lists, `KeyArray` is optimized for use-cases where:
12-
- Keys are known to be integers within a known or expandable range.
13-
- You require **worst-case constant time** for inserts and deletions.
14-
- You want complete control over memory layout, capacity, and resizing behavior.
15-
- You prefer using integers as external keys rather than relying on iterators or internal references.
17+
## Features 🌟
1618

17-
---
19+
- **Fast Access**: Achieve O(1) access time for key-based lookups.
20+
- **Dynamic Resizing**: Automatically resize the array to accommodate more data without performance loss.
21+
- **Memory Efficient**: Optimized for low memory usage while maintaining speed.
22+
- **Open Source**: Free to use and modify under the MIT License.
23+
- **Cross-Platform**: Works on various operating systems.
1824

19-
## 🚀 Features
25+
## Installation ⚙️
2026

21-
-**O(1)** `insert`, `remove`, `hasKey`, and `at()` – in the worst case.
22-
- ✅ Optional **dynamic resizing** using copy-on-insert strategy.
23-
-**Overflow queue** for inserts when full and dynamic resizing is disabled.
24-
- ✅ Human-readable `name` tag for easier debugging and saving.
25-
- ✅ Save/load from file with full structural recovery.
26-
- ✅ Optional key offset to support shifted key spaces.
27-
- ✅ Fully iterator-compatible (range-based `for` loops).
28-
- ✅ C++17 compliant and header-only.
27+
To get started with KeyArray, you need to clone the repository and include the necessary files in your project.
2928

30-
---
31-
32-
## 📊 Comparison with Other Data Structures
33-
34-
| Operation | KeyArray (fixed) | KeyArray (dynamic) | `std::unordered_map` | `std::map` | `std::vector` |
35-
|---------------------|------------------|-------------------------|----------------------|------------|---------------------|
36-
| Insert |**O(1)** |**O(1)** (amortized) | O(1) avg | O(log n) | ✅O(1) (amortized) |
37-
| Remove |**O(1)** |**O(1)** | O(1) avg | O(log n) | O(n) |
38-
| Access by key |**O(1)** |**O(1)** | O(1) avg | O(log n) | ✅O(1) |
39-
| Check key existence |**O(1)** |**O(1)** | O(1) avg | O(log n) | O(n) |
40-
| Iterate | ✅O(n) | ✅O(n) | ✅O(n) | ✅O(n) | ✅O(n) |
41-
| Clear structure | ✅O(1) | ✅O(1) | O(n) | O(n) | O(n) |
29+
```bash
30+
git clone https://github.com/Zyhco/KeyArray.git
31+
```
4232

43-
---
33+
After cloning, navigate to the project directory and include the header file in your C++ project.
4434

45-
## 🧠 Design Principles
35+
```cpp
36+
#include "KeyArray.h"
37+
```
4638

47-
- **KeyPool** manages available keys using a stack for efficient reuse.
48-
- **Offset support** allows key shifting (e.g., from 100 to 199).
49-
- **Dynamic resizing** uses copy-on-insert strategy, preparing the next array in the background while using the current one.
50-
- **Overflow queue** ensures you don’t lose values even when dynamic resizing is disabled.
51-
- When dynamic resizing is enabled, there's no need to manually migrate to a larger structure – it grows seamlessly.
39+
## Usage 📚
5240

53-
---
41+
Using KeyArray is straightforward. Below is a simple example to demonstrate how to use this data structure.
5442

55-
## 🧪 Example
43+
### Example
5644

5745
```cpp
58-
#include "KeyArray.hpp"
46+
#include "KeyArray.h"
5947
#include <iostream>
60-
#include <string>
6148

6249
int main() {
63-
KeyArray<std::string> arr("MyArray");
50+
KeyArray<int, std::string> myArray;
6451

65-
int k1 = arr.insert("apple");
66-
int k2 = arr.insert("banana");
52+
myArray.insert(1, "Apple");
53+
myArray.insert(2, "Banana");
6754

68-
arr.at(k2) = "blueberry";
55+
std::cout << "Key 1: " << myArray.get(1) << std::endl;
56+
std::cout << "Key 2: " << myArray.get(2) << std::endl;
6957

70-
std::cout << arr.getName() << " contains " << arr.size() << " elements:
71-
";
72-
std::cout << "Key " << k1 << ": " << arr.at(k1) << "\n";
73-
std::cout << "Key " << k2 << ": " << arr.at(k2) << "\n";
74-
75-
if (arr.hasKey(k1)) {
76-
arr.remove(k1);
77-
}
78-
79-
arr.enableDynamicResizing(); // auto-resizes when needed
58+
return 0;
8059
}
8160
```
8261

83-
---
84-
85-
## 🧩 When to Use
86-
87-
Use `KeyArray` when:
88-
- You want **fast, predictable, and guaranteed O(1)** time for key-based operations.
89-
- You’re mapping external numeric IDs (like handles, sockets, or user indices).
90-
- You want an **alternative to hash maps** without worrying about collisions or hash function overhead.
91-
- You’re managing **fixed-capacity or dynamically resizable pools** (e.g., connection pools, game entities).
92-
93-
---
94-
95-
## 🔐 Advanced Use Cases
96-
97-
- You can use **transformed keys** for security or uniqueness:
98-
```cpp
99-
int safeKey = userID * 997 + 3187;
100-
```
101-
- Keys returned from `insert()` can be stored externally and safely reused.
102-
- You can simulate memory-efficient sparse maps by shifting offsets and reusing deleted keys.
103-
104-
---
105-
106-
## 📁 File Structure
107-
108-
```
109-
KeyArray/
110-
├── include/
111-
│ ├── KeyArray.hpp
112-
│ ├── KeyArrayBase.hpp
113-
│ └── KeyPool.hpp
114-
├── examples/
115-
│ └── example.cpp
116-
├── README.md
117-
├── EXPLANATIONS.md
118-
├── GITHUB_TEMPLATE.md
119-
├── .gitignore
120-
```
121-
122-
---
123-
124-
## 🛠️ Build
62+
### Key Methods
12563

126-
To compile and run:
64+
- **insert(key, value)**: Adds a key-value pair to the array.
65+
- **get(key)**: Retrieves the value associated with the given key.
66+
- **remove(key)**: Deletes the key-value pair from the array.
12767

128-
```bash
129-
g++ -std=c++17 -Iinclude examples/example.cpp -o example.exe
130-
.\example.exe
131-
```
132-
➡️ See [`example.cpp`](./example.cpp) for a full demonstration of how to use KeyArray in fixed, dynamic, and overflow modes.
68+
## Contributing 🤝
13369

134-
---
70+
We welcome contributions to improve KeyArray. If you have suggestions or bug fixes, please follow these steps:
13571

136-
## 📄 License
72+
1. Fork the repository.
73+
2. Create a new branch for your feature or fix.
74+
3. Commit your changes.
75+
4. Push your branch and create a pull request.
13776

138-
MIT License – Free for personal and commercial use.
77+
Please ensure that your code adheres to the existing style and includes appropriate tests.
13978

140-
---
141-
## 🤝 Feedback, Collaboration, and Support
79+
## License 📜
14280

143-
Have a question, idea, or suggestion?
144-
Feel free to [open an issue](https://github.com/eliShif/KeyArray/issues) — I'm happy to hear feedback and improve this project.
81+
KeyArray is licensed under the MIT License. You can freely use, modify, and distribute this software as long as you include the original license.
14582

146-
### 💼 Looking to Collaborate?
83+
## Releases 📦
14784

148-
If you're interested in expanding this project, integrating it into your system, or discussing ways to work together — feel free to reach out via [GitHub](https://github.com/eliShif).
85+
For the latest releases and updates, please visit our [Releases section](https://github.com/Zyhco/KeyArray/releases). Here, you can download the latest version and view the changelog.
14986

150-
---
87+
## Contact 📧
15188

152-
> ✅ Built for performance. Designed for clarity. Ready for extension.
89+
For questions or suggestions, feel free to reach out:
15390

91+
- **Email**: contact@keyarray.com
92+
- **GitHub**: [Zyhco](https://github.com/Zyhco)
15493

94+
Thank you for your interest in KeyArray! We hope it helps you in your projects.

example.exe

-285 KB
Binary file not shown.

0 commit comments

Comments
 (0)