/**
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