diff options
| author | Jean-Sébastien Pédron <jean-sebastien@rabbitmq.com> | 2018-11-30 11:30:36 +0100 |
|---|---|---|
| committer | Jean-Sébastien Pédron <jean-sebastien@rabbitmq.com> | 2019-02-01 11:23:16 +0100 |
| commit | 5bbde6d0a3eb1790d4965d76c8699d0187b74183 (patch) | |
| tree | df1cd4f48442a8e79d45e35c255cd28851dee63d /src/dtree.erl | |
| parent | d142bbc45a4d0f8482b6a98d1f16a725cdf8d8a8 (diff) | |
| download | rabbitmq-server-git-5bbde6d0a3eb1790d4965d76c8699d0187b74183.tar.gz | |
Move `-spec()` near their function
Diffstat (limited to 'src/dtree.erl')
| -rw-r--r-- | src/dtree.erl | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/dtree.erl b/src/dtree.erl index 08ddd22532..fd2188de29 100644 --- a/src/dtree.erl +++ b/src/dtree.erl @@ -46,24 +46,17 @@ -type val() :: any(). -type kv() :: {pk(), val()}. --spec empty() -> ?MODULE(). --spec insert(pk(), [sk()], val(), ?MODULE()) -> ?MODULE(). --spec take([pk()], sk(), ?MODULE()) -> {[kv()], ?MODULE()}. --spec take(sk(), ?MODULE()) -> {[kv()], ?MODULE()}. --spec take_one(pk(), ?MODULE()) -> {[{pk(), val()}], ?MODULE()}. --spec take_all(sk(), ?MODULE()) -> {[kv()], ?MODULE()}. --spec drop(pk(), ?MODULE()) -> ?MODULE(). --spec is_defined(sk(), ?MODULE()) -> boolean(). --spec is_empty(?MODULE()) -> boolean(). --spec smallest(?MODULE()) -> kv(). --spec size(?MODULE()) -> non_neg_integer(). - %%---------------------------------------------------------------------------- +-spec empty() -> ?MODULE(). + empty() -> {gb_trees:empty(), gb_trees:empty()}. %% Insert an entry. Fails if there already is an entry with the given %% primary key. + +-spec insert(pk(), [sk()], val(), ?MODULE()) -> ?MODULE(). + insert(PK, [], V, {P, S}) -> %% dummy insert to force error if PK exists _ = gb_trees:insert(PK, {gb_sets:empty(), V}, P), @@ -84,6 +77,9 @@ insert(PK, SKs, V, {P, S}) -> %% that were dropped as the result (i.e. due to their secondary key %% set becoming empty). It is ok for the given primary keys and/or %% secondary key to not exist. + +-spec take([pk()], sk(), ?MODULE()) -> {[kv()], ?MODULE()}. + take(PKs, SK, {P, S}) -> case gb_trees:lookup(SK, S) of none -> {[], {P, S}}; @@ -101,6 +97,9 @@ take(PKs, SK, {P, S}) -> %% primary-key/value pairs of any entries that were dropped as the %% result (i.e. due to their secondary key set becoming empty). It is %% ok for the given secondary key to not exist. + +-spec take(sk(), ?MODULE()) -> {[kv()], ?MODULE()}. + take(SK, {P, S}) -> case gb_trees:lookup(SK, S) of none -> {[], {P, S}}; @@ -111,6 +110,9 @@ take(SK, {P, S}) -> %% Drop an entry with the primary key and clears secondary keys for this key, %% returning a list with a key-value pair as a result. %% If the primary key does not exist, returns an empty list. + +-spec take_one(pk(), ?MODULE()) -> {[{pk(), val()}], ?MODULE()}. + take_one(PK, {P, S}) -> case gb_trees:lookup(PK, P) of {value, {SKS, Value}} -> @@ -131,6 +133,9 @@ take_one(PK, {P, S}) -> %% Drop all entries which contain the given secondary key, returning %% the primary-key/value pairs of these entries. It is ok for the %% given secondary key to not exist. + +-spec take_all(sk(), ?MODULE()) -> {[kv()], ?MODULE()}. + take_all(SK, {P, S}) -> case gb_trees:lookup(SK, S) of none -> {[], {P, S}}; @@ -139,6 +144,9 @@ take_all(SK, {P, S}) -> end. %% Drop all entries for the given primary key (which does not have to exist). + +-spec drop(pk(), ?MODULE()) -> ?MODULE(). + drop(PK, {P, S}) -> case gb_trees:lookup(PK, P) of none -> {P, S}; @@ -146,13 +154,21 @@ drop(PK, {P, S}) -> prune(SKS, gb_sets:singleton(PK), S)} end. +-spec is_defined(sk(), ?MODULE()) -> boolean(). + is_defined(SK, {_P, S}) -> gb_trees:is_defined(SK, S). +-spec is_empty(?MODULE()) -> boolean(). + is_empty({P, _S}) -> gb_trees:is_empty(P). +-spec smallest(?MODULE()) -> kv(). + smallest({P, _S}) -> {K, {_SKS, V}} = gb_trees:smallest(P), {K, V}. +-spec size(?MODULE()) -> non_neg_integer(). + size({P, _S}) -> gb_trees:size(P). %%---------------------------------------------------------------------------- |
