Java CRC16 algorithm, decomposition of a large key instance. And all kinds of hash algorithm code __ algorithm

Source: Internet
Author: User
Tags redis
[Java]   View Plain  copy   package org.rui.hi;     /**   *  test:  Solution scenario: 100 million of users   stored in a queue, too large. redis  cluster  sharding Redis   *  with sharding  The cluster uses data fragmentation (sharding) rather than a consistent hash (consistency hashing) to implement:  a  Redis  cluster contains  16384   *   Hash slot (Hash slot),  each key in the database belongs to one of these  16384  hash slots,  The cluster uses the formula &NBSP;CRC16 (key)  %  16384  to compute key    * key  slot,  where &NBSP;CRC16 (key)   statement is used to compute key  key   CRC16  checksum  .    *    *  @author  ruiliang   *   */   public  class hashdist {       public final static int  MAXINT&NBSP;=&NBSP;1000;//&NBSP;00000;//1 billion        public final static  int USER_KEY_SLOT_COUNT = 20; //  Fixed allocation storage user's SLOT bit                                                              &NBSP;//&NBSP, if the storage has pressure, adjustable slot           public static void  Main (String[] args)  {              //  int  without crc16           for  (int i =  1; i < maxint; i++)  {                //  assign to slot bit           according to player id  distribution       int ranint = i % USER_KEY_SLOT_COUNT;               string key =  "key:"  + ranint;                system.out.println ("Key:"  + key);               //  Redislist.lpush (randomkey, string.valueof (playerID));            }              /**            * crc16 redis  clusters are also allocating key  in this way           */               string a =  "A,b,c,d,e,f,g,g,g";           for   (String j : a.split (","))  {             &NBSP;&NBSP;&NBSP;INT&NBSP;SOLT&NBSP;=&NBSP;CRCJAVA.CRC16 (J.getbytes ())  % USER_KEY_SLOT_COUNT;                String key =  "key : " + solt;                System.out.println ("Crc%solt=key:"  + key);            }              // redislist.lpush ( Randomkey, string.valueof (playerID));          }      }  /** 
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.