Skip to content

Commit

Permalink
feat(docs,jsdoc): update readme, add JSDoc to RR cache
Browse files Browse the repository at this point in the history
  • Loading branch information
zhibirc committed Nov 24, 2023
1 parent 29191e3 commit 054af89
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: npm-test

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# ururu

![Maintenance](https://img.shields.io/maintenance/yes/2023?color=brightgreen&style=flat-square)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-magenta.svg)]()
[![Maintenance](https://img.shields.io/maintenance/yes/2023.svg?style=flat)]()
![GitHub repo size](https://img.shields.io/github/repo-size/zhibirc/ururu?style=flat&color=008080)
![Static Badge](https://img.shields.io/badge/cache_algorithms-7-f0e68c)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg?style=flat)]()

<h3 align="center">🐦</h3>
<p align="center">
<img width="400" src="ururu.jpeg">
</p>

---

**No URURU, just LRU (and friends)**

Expand Down
19 changes: 19 additions & 0 deletions rr-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class RRCache implements IRRCache {
this.#capacity = value;
}

/**
* Read value stored in cache by assosiated key.
* @param {*} key - cache record's key
* @return {*|null} record's value retrieved by key or null if record is absent
*/
read (key: any) {
if (this.#store.has(key)) {
return this.#store.get(key).value;
Expand All @@ -57,10 +62,20 @@ class RRCache implements IRRCache {
this.#store.set(key, {keyIndex, value});
}

/**
* Check if record by given key exists in cache.
* @param {*} key - cache record's key
* @return {boolean} return true if record is in the cache
*/
has (key: any) {
return this.#store.has(key);
}

/**
* Remove an item from the cache.
* @param {*} key - cache record's key
* @return {void}
*/
remove (key: any) {
if (this.#store.has(key)) {
const keyIndex = this.#store.get(key).keyIndex;
Expand All @@ -70,6 +85,10 @@ class RRCache implements IRRCache {
}
}

/**
* Remove all items from the cache.
* @return {void}
*/
clear () {
this.#keys.length = this.#freeSlots.length = 0;
this.#keys.length = this.#capacity;
Expand Down
Binary file added ururu.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 054af89

Please sign in to comment.