about sorted set

37 views
Skip to first unread message

Lin

unread,
Jan 2, 2013, 11:53:12 PM1/2/13
to redi...@googlegroups.com
Hello guys,

I am learning Sorted Set from here (http://redis.io/topics/data-types), I am confused by the following statements, especially confused by the statement "Since elements are taken in order and not ordered afterwards". I am wondering what means "taken in order and not ordered afterwards"? Appreciate if anyone could show me an example? Thanks.

With sorted sets you can add, remove, or update elements in a very fast way (in a time proportional to the logarithm of the number of elements). Since elements are taken in order and not ordered afterwards, you can also get ranges by score or by rank (position) in a very fast way. Accessing the middle of a sorted set is also very fast, so you can use Sorted Sets as a smart list of non repeating elements where you can quickly access everything you need: elements in order, fast existence test, fast access to elements in the middle!


regards,
Lin

Didier Spezia

unread,
Jan 4, 2013, 3:43:22 AM1/4/13
to redi...@googlegroups.com
Hi Lin,

it just means the data structure used to represent a sorted set (i.e. a dictionary plus a skip list),
does enforce the order by keeping a sorted view of the items (in the skip list).

So when you need to retrieve the item by score and value order, there is no further processing
to do except walking through the skip list. In other words, order is enforced at insert time,
not at retrieve time.

Regards,
Didier.

Lin

unread,
Jan 4, 2013, 6:03:45 AM1/4/13
to redi...@googlegroups.com
Hi Didier, thanks for the detailed reply. For sorted set, I think if we could have a skip list to store sorted values by score, it should be enough. Why we need another dictionary?

regards,
Lin

Didier Spezia

unread,
Jan 4, 2013, 7:44:02 AM1/4/13
to redi...@googlegroups.com

Because a sorted set is also a set, and therefore we should be able to quickly
check for membership, delete an item per value, increase the score for a given
value, etc ... For these operations, the score is not provided in the input query,
so if we only had a data structure indexed with the score, it would result in
linear searches.


Regards,
Didier.

Lin

unread,
Jan 4, 2013, 8:05:06 AM1/4/13
to redi...@googlegroups.com
Thanks Didier, my question is answered.

regards,
Lin
Reply all
Reply to author
Forward
0 new messages