9.10 Extensibility and storage Limitations (i)-for ultra-large social networking sites, show "Connection" or "social pathways" between two people

Source: Internet
Author: User

/**
function
/** * Idea: * 1) for each friend ID, find out where the machine is located: int machine_index=getmachineidforuser (PersonID); * 2) Go to the machine numbered #machine_index. * 3) on that machine, execute: Person Friend=getpersonwithid (person_id). * * Defines a server class that contains a list of all machines, and a machine class that represents a single computer. Find data effectively with a hash table. * */class server{hashmap<integer,machine> machines=new Hashmap<integer, machine> (); Hashmap<integer,integer> persontomachinemap=new Hashmap<integer, integer> ();p ublic Machine Getmachinewithid (int machineid) {return machines.get (MachineID);} public int getmachineidforuser (int personID) {return persontomachinemap.get (PersonID);} Public person Getpersonwithid (int personID) {Integer machineid=getmachineidforuser (PersonID); if (machineid==null) return null; Machine Machine=getmachinewithid (MachineID); if (machine==null) return Null;return Machine.getpersonwithid (PersonID) ;}} Class Machine{public int machineid;public hashmap<integer,person> persons=new Hashmap<integer, Person> (); Public person Getpersonwithid (int personID) {return Persons.get (PersonID);}} Class Person{private int personid;private arraylist<integer> friendid;public person (int id) {this.personid=id;} public int GetID () {return this.personid;} public void addfriend (int id) {this.friendID.add (id);}} /** * Optimization: Reduce the number of hops between machines * It is expensive to jump from one machine to another, instead of jumping between machines in order to find a friend, try to batch these jumps. * Optimization: Intelligent division of users and machines * based on geographical division * PROBLEM: Breadth-first search requires tagging of visited nodes, how to process * Many search operations may be performed at the same time, so it is not appropriate to edit the data directly. You can use a hash table to mimic the tag action of a node to query the node ID and whether it has been accessed. */


*/

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

9.10 Extensibility and storage Limitations (i)-for ultra-large social networking sites, show "Connection" or "social pathways" between two people

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.