Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure if you're asking how to make suggestions or detect friend distance. Making suggestions is easy, but will tend to explode in size.</p> <p>The first two cases can be covered by the same algorithm, and the third by a small extension.</p> <p>The first two are basically looking for all the people who your known friends mutually know:</p> <pre><code>FriendHash = {} foreach Friend in me.getFriends() foreach FriendOfFriend in Friend.getFriends() FriendHash{FriendOfFriend} += 1 foreach PotentialFriend in keys FriendHash if FriendHash{PotentialFriend} &gt; 1 me.suggestFriend(PotentialFriend) </code></pre> <p>In case 1, the link between friends 1 and 2 could be an additional constraint that would actually make the case a bit more complex to implement. By requiring friends 1 and 2 to have a link, you'd need to detect potential friends while iterating friend pairs, rather than once at the end.</p> <pre><code>foreach Friend in me.getFriends() foreach SecondFriend in me.getFriends() # skip already processed friends and Friend == SecondFriend if Friend.getFriends() contains SecondFriend foreach FriendOfFriend in Friend.getFriends() # skip already suggested friends if SecondFriend.getFriends() contains FriendOfFriend me.suggestFriend(PotentialFriend) </code></pre> <p>There's certainly some optimization that can be added in there that would skip repeated comparisons. In practice this probably isn't a useful search to run anyway. All you're going to do is exclude potential friends who are common to two distinct groups of friends.</p> <p>The last case modifies the first pseudo code segment by extending a friend suggestion to all the friends of your known friends mutual friends:</p> <pre><code>foreach PotentialFriend in keys FriendHash if FriendHash{PotentialFriend} &gt; 1 foreach ExtendedFriend in PotentialFriend.getFriends() me.suggestFriend(ExtendedFriend) </code></pre> <p>As commented by Neil Knight, you could filter each friend list and start by looking at the most active friends first. Or compute a similarity score that promotes those friends who have more friends in common with you.</p> <p>If you're actually looking at detecting the distance between a friend and a suggestion, this probably isn't relevant.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload