Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:26
erlang
2866-snmp-Types-and-specs-for-snmp_index-get_la...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2866-snmp-Types-and-specs-for-snmp_index-get_last-1.patch of Package erlang
From c9e64a0b91a170df0259c0b744eae5b458d3233e Mon Sep 17 00:00:00 2001 From: Micael Karlberg <bmk@erlang.org> Date: Mon, 15 Jan 2024 14:36:41 +0100 Subject: [PATCH 46/67] [snmp] Types and specs for snmp_index:get_last/1 --- lib/snmp/doc/src/snmp_index.xml | 36 ++++++++++++++----------------- lib/snmp/src/agent/snmp_index.erl | 25 +++++++++++++-------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/lib/snmp/doc/src/snmp_index.xml b/lib/snmp/doc/src/snmp_index.xml index 8b6fbfe3e8..94f6a15e8c 100644 --- a/lib/snmp/doc/src/snmp_index.xml +++ b/lib/snmp/doc/src/snmp_index.xml @@ -130,17 +130,17 @@ get_next_pid(Oid, SnmpIndex) -> <datatype> <name name="key"/> <desc> - <p> - This type correlates to the - <seetype marker="#key_types">key_types()</seetype> - type. - If the - <seetype marker="#key_types">key_types()</seetype> - is a single atom, the corresponding <c>key()</c> - is a single type as well, but if the - <seetype marker="#key_types">key_types()</seetype> - is a tuple, <c>key()</c> must be a tuple of the same size. - </p> + <p>This type correlates to the + <seetype marker="#key_types">key_types()</seetype> + type. If the <seetype marker="#key_types">key_types()</seetype> + is a single atom, the corresponding <c>key()</c> + is a single type as well, but if the + <seetype marker="#key_types">key_types()</seetype> + is a tuple, <c>key()</c> must be a tuple of the same size. </p> + <p>In the example above, valid <c>keys</c> could be + <c>{"hi", "mom"}</c> and <c>{"no", "thanks"}</c>, whereas <c>"hi"</c>, + <c>{"hi", 42}</c> and <c>{"hello", "there"}</c> would be invalid.</p> + <p>There is no way to propely describe this type in the erlang type language, which is why <c>tuple()</c> was used above. The proper definition looks like: </p> @@ -162,7 +162,7 @@ get_next_pid(Oid, SnmpIndex) -> <p><c>oid() = [byte()]</c></p> </item> <item> - <p><c>key_types = type_spec() | {type_spec(), type_spec(), ...}</c></p> + <p><c>key_types = type_spec() | {type_spec(), type_spec(), ...}</c></p> </item> <item> <p><c>type_spec() = fix_string | string | integer</c></p> @@ -263,17 +263,13 @@ get_next_pid(Oid, SnmpIndex) -> </func> <func> - <name since="">get_last(Index) -> {ok, {KeyOid, Value}} | undefined</name> + <name name="get_last" arity="1" clause_i="1" since=""/> <fsummary>Get the last item in the index structure</fsummary> - <type> - <v>Index = index()</v> - <v>KeyOid = oid()</v> - <v>Value = term()</v> - </type> <desc> <p>Gets the last item in the index structure.</p> </desc> </func> + <func> <name since="">get_next(Index, KeyOid) -> {ok, {NextKeyOid, Value}} | undefined</name> <fsummary>Get the next item</fsummary> @@ -284,8 +280,8 @@ get_next_pid(Oid, SnmpIndex) -> </type> <desc> <p>Gets the next item in the SNMP lexicographic ordering, - after <c>KeyOid</c> in the index structure. <c>KeyOid</c> - does not have to refer to an existing item in the index.</p> + after <c>KeyOid</c> in the index structure. <c>KeyOid</c> + does not have to refer to an existing item in the index.</p> </desc> </func> <func> diff --git a/lib/snmp/src/agent/snmp_index.erl b/lib/snmp/src/agent/snmp_index.erl index ee8bff5972..c6a309813d 100644 --- a/lib/snmp/src/agent/snmp_index.erl +++ b/lib/snmp/src/agent/snmp_index.erl @@ -114,6 +114,22 @@ get(#tab{id = OrdSet}, KeyOid) -> +-spec get_last(Index) -> {ok, {KeyOid, Value}} | undefined when + Index :: index(), + KeyOid :: snmp:oid(), + Value :: term(). + +get_last(#tab{id = OrdSet} = Index) -> + ?vlog("get_last -> entry with" + "~n OrdSet: ~p", [OrdSet]), + case ets:last(OrdSet) of + '$end_of_table' -> + undefined; + Key -> + get(Index, Key) + end. + + get_next(#tab{id = OrdSet} = Tab, KeyOid) -> ?vlog("get_next -> entry with" "~n Tab: ~p" @@ -125,15 +141,6 @@ get_next(#tab{id = OrdSet} = Tab, KeyOid) -> get(Tab, Key) end. -get_last(#tab{id = OrdSet} = Tab) -> - ?vlog("get_last -> entry with" - "~n Tab: ~p", [Tab]), - case ets:last(OrdSet) of - '$end_of_table' -> - undefined; - Key -> - get(Tab, Key) - end. insert(#tab{id = OrdSet, keys = KeyTypes} = Tab, Key, Val) -> ets:insert(OrdSet, {key_to_oid_i(Key, KeyTypes), Val}), -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor