How to order items in ETS?
i insert many items in ETS like this:
ets:insert{{users, jim, 9}}
ets:insert{{users, ham, 3}}
ets:insert{{users, why, 2}}
ets:insert{{users, dhh, 3}}
ets:insert{{users, zend, 4}}
so how to get the ordered list by one number in item?
[
{users, why, 2},
{use开发者_如何学运维rs, ham, 3},
{users, dhh, 3},
{users, zend, 4},
{users, jim, 9}
]
By using lists:keysort/2
like so:
1> Result = [{users, jim, 9},
{users, ham, 3},
{users, why, 2},
{users, dhh, 3},
{users,zend, 4}].
[{users,jim,9},
{users,ham,3},
{users,why,2},
{users,dhh,3},
{users,zend,4}]
2> lists:keysort(3, Result).
[{users,why,2},
{users,ham,3},
{users,dhh,3},
{users,zend,4},
{users,jim,9}]
精彩评论