forked from jl777/SuperNET
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use
timed-map
crate instead of internal ExpirableMap
type
- Loading branch information
Showing
12 changed files
with
62 additions
and
181 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! This module provides a cross-compatible map that associates values with keys and supports expiring entries. | ||
//! | ||
//! Designed for performance-oriented use-cases utilizing `FxHashMap` under the hood, | ||
//! and is not suitable for cryptographic purposes. | ||
use instant::{Duration, Instant}; | ||
#[derive(Clone, Debug)] | ||
pub struct ExpirableEntry<V> { | ||
pub(crate) value: V, | ||
pub(crate) expires_at: Instant, | ||
} | ||
|
||
impl<V> ExpirableEntry<V> { | ||
#[inline(always)] | ||
pub fn new(v: V, exp: Duration) -> Self { | ||
Self { | ||
expires_at: Instant::now() + exp, | ||
value: v, | ||
} | ||
} | ||
|
||
#[inline(always)] | ||
pub fn get_element(&self) -> &V { &self.value } | ||
|
||
#[inline(always)] | ||
pub fn update_value(&mut self, v: V) { self.value = v } | ||
|
||
#[inline(always)] | ||
pub fn update_expiration(&mut self, expires_at: Instant) { self.expires_at = expires_at } | ||
|
||
/// Checks whether entry has longer ttl than the given one. | ||
#[inline(always)] | ||
pub fn has_longer_life_than(&self, min_ttl: Duration) -> bool { self.expires_at > Instant::now() + min_ttl } | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.