What is a set in C?A set containing non-repeating elements is called "set )".. NET4 contains two sets (HashSet The ISet Case:// Use HashSet: repeated elements are automatically removed but not sorted.Var set = new HashSet In the same code, replace HashSet with SortedSet:// Use SortedSet: repeated elements are automatically removed and sorted.VAr set = new Sort
The SortedSet in set (SortedSet is the implementation interface for TreeSet), and the inheritance between them is as follows:Java.util.Set;Java.util.SortedSet;Java.util.TreeSet;The elements in the SortedSet are unordered and cannot be duplicated, but the elements that are stored can be sorted automatically in order of the element size. Combine the following code
[Java class set] _ sortedset interface notes
Objectives of this chapter:Understanding the relationship between sortedset interface and set InterfaceMeasure the test taker's knowledge about common sortedset operations.
3. DetailsThe treeset class is an operation class that can be sorted. Treeset is actually a subclass of the s
Microsoft has added a HashSet class to. NET 3.5, adding a SortedSet class to. NET 4, which describes their features and compares their similarities and differences.
The HashSet and SortedSet classes of the. NET Collection function Library implement the System.Collections.Generic.ISet interface, but Java versions earlier than 1.2 (or earlier) have provided implementations that Two kinds of data structures h
SetA collection of non-repeating elements is called a set. . The NET4 contains two sets (hashset and sortedset They all implement iset interface . Hashset is an unordered list that contains non-repeating elements ,sortedset The set contains an ordered list of non-repeating elements .the Iset collections, intersections , or information that gives a superset or subset of another set when one is set .Case :use
SORTEDSET data Structures SortedSet and set types are very similar, and they are all collections of strings that do not allow duplicate members to appear in a set collection. The main difference between them is that each member of the SortedSet will have a fraction (score) associated with it, and Redis is the sort of the large to the small for the members of the
There are many sorting algorithms in C and C ++, but usually the sorting algorithm has to put programmers into an understanding of many pointers and positions at the underlying layer during code writing. Java does not want this, therefore, most sorting tasks can be done by Java. For example, if you want to sort an array, you can use:Collections. Sort (list)The list will be sorted.Arrays. SortSo the array is naturally usedArrays. SortAndSortedsetThe sorting function is also implemented in a simil
We know that set set can hold a series of objects, such as Int,class, and are unordered and non-repeatable. Today we are going to discuss:set can be sorted, how to customize the collationFirst, steal a graph to illustrate the inheritance relationship of set:Today we mainly discuss the usage of sortedset.(Note: All are excuses, need to use their implementation class)Let's implement the SortedSet sort:public
Collection sub-interface (List/Set/Queue/SortedSet), queuesortedsetMain sub-interfaces of Collection:
List: stores duplicate content.
Set: duplicate content cannot be stored. All duplicate content is differentiated by hashCode () and equals ().
Queue: Queue Interface
SortedSet: sorts data in a set.
List interface: summarizes the extension methods of the List interface, that is, adding, deleting, modi
SortedSet Interface for TreeSet preparationYou can implement a sorted collectionSourcePackage Java.util;public Interface Sortedsetif and* toOne another using this *Set' s Comparator (or,if the SetHas no comparator, using * natural ordering). Implementations May, butIs notRequired * to, throw this exceptionifor* toElements currentlyinch* the Set. * @throws NullPointerExceptionifor* isNull andThisSet does notPermit NULL * elements * @throws illegal
Reference: http://www.lurenjia.net/article.asp? Id = 233 and http://csourcesearch.net/java/fidAB55053EB2EBD58B30F9B28C706AAF40861E637C.aspx? S = mdef % 3 ainsert
A colleague needs to filter strings and sort them during the project process, for example, input:
111-1111131-1111111-1111131-1111121-1221111-1111111-1111Output:111-1111121-1221131-1111
If you want to filter duplicates, you can use set, because the set does not allow repeated elements. As for sorting, the collections sort method c
Main sub-interfaces of collection:
List: stores duplicate content.
Set: duplicate content cannot be stored. All duplicate content is differentiated by hashcode () and equals ().
Queue: queue Interface
Sortedset: sorts data in a set.
List interface: summarizes the extension methods of the List interface, that is, adding, deleting, modifying, and querying methods.
A common subclass of the List interface: arraylist: The list interface can be in
In-game leaderboard is a very common requirement, previously used by Redis SortedSet, just see a LUA implementation, and then ported to the Golang version, GitHub address: Https://github.com/Skycrab/go-zset , the CLI commands for using the method and Redis are basically consistent.Using the CGO package, the implementation of the skiplist is basically the same as Redis, although CGO is very convenient to use, but it involves a callback to go in C.It do
static void main (string [] ARGs) {shortlist
2. Set Interface
The Set interface is also a sub-interface of collection. The objects in the list container can be repeated, but the objects in the Set container must be unique.
The hashset class implements the set interface. Hashset uses the hash method to insert and sort elements, so that it can be efficiently searched and inserted. For example:
Package CLS; import Java. util. *;/*** use hashset for quick search and insert operations * 2013.3.22
Redis defaults to only support the expiration of simple keys, such as the SortedSet type, but also for the entire set of expired processing, does not support the expiration of a member of set;In order to solve this problem, the following are done:1. Store key and value information to Redis and put key in set to set key expiration time;This key can support expiration processing and remove key and value after expiration, but the key in set still exists;
Package Cn.com;import Java.util.hashmap;import java.util.map;import java.util.set;import Redis.clients.jedis.Jedis; Import redis.clients.jedis.tuple;/** * All operation Methods of an ordered set * * */public class Redis_sortedset {public static Jedis Redis = new Je Dis ("localhost", 6379);//Connect Redis/** * Zadd key score member [[Score member] [SCORE member] ...] * One or more member elements and their SCO The RE value is added to the ordered set key. * If a member is already a member of an o
Hashset Sortedset Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; namespace consoleapplication8 {class program {static void main (string [] ARGs) {// ============================ [hashset This article from the "programmer's home" blog, please be sure to keep this source http://962410314.blog.51cto.com/7563109/1548502 Set --- hashset
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.