Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ObliviousLRUCache with delete functionality #162

Closed
wants to merge 1 commit into from
Closed

feat: add ObliviousLRUCache with delete functionality #162

wants to merge 1 commit into from

Conversation

trivikr
Copy link
Contributor

@trivikr trivikr commented May 6, 2021

Fixes: #143

This PR creates ObliviousLRUCache with delete functionality.

Changes done:

  • Inherit ObliviousLRUCache from LRUCache.
  • Add delete functionality using a PointerArray to store deleted pointers.
  • Added tests.
  • Added types.

@trivikr trivikr changed the title feat: create ObliviousLRUCache with delete functionality feat: add ObliviousLRUCache with delete functionality May 6, 2021
Copy link
Owner

@Yomguithereal Yomguithereal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @trivikr, thanks for this new PR. I have added some comments on this review. Have a good day.

*/
import {IArrayLikeConstructor} from './utils/types';

export default class ObliviousLRUCache<K, V> implements Iterable<[K, V]> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be wrong but I think you can import the LRUCache class in this definition file and make this class definition extends it, no?

setpop(key: K, value: V): {evicted: boolean, key: K, value: V};
get(key: K): V | undefined;
peek(key: K): V | undefined;
remove(key: K): this;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be delete :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And probably return boolean, based on next comment.

}

if (this.head === pointer && this.tail === pointer) {
this.clear();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using #.clear here will reallocate the #.items object. Resetting head, tail and size to 0 should do the trick? Your condition can be simplified to this.size === 1 to be more performant if I understand the problem correctly.

* @param {any} key - Key.
* @return {undefined}
*/
ObliviousLRUCache.prototype.delete = function(key) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method could a boolean indicating whether an item was delete, like the ES6 Map does, no?

@@ -215,8 +216,52 @@ function makeTests(Cache, name) {

assert.deepStrictEqual(entries, Array.from(cache.entries()));
});

if (name === 'ObliviousLRUCache') {
it('should be possible to delete keys from a LRU cache.', function() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering whether a rolling test should be done? Like add 2 remove 1, in a loop of ~10 items for a cache of ~4-5 capacity.

@Yomguithereal
Copy link
Owner

Any update on this @trivikr?

@trivikr
Copy link
Contributor Author

trivikr commented Nov 17, 2021

Superceded by #173

@trivikr trivikr closed this Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LRU remove by key
2 participants