Is there an elegant way to store a dual relationship (i.e. user 1 and user 2 are friends)

前端 未结 5 1101
野趣味
野趣味 2020-12-16 06:01

I\'ve run into the same problem in two different pieces of work this month:

Version 1: User 1 & User 2 are friends
Version 2: Axis 1 & Axis 2 when gr         


        
5条回答
  •  情歌与酒
    2020-12-16 06:58

    For anyone that's interested, I played around with a few bitwise operations and found that the following seems to fulfill the criteria for f(x,y):

    #Python, returns 3 tuple
    def get_hash(x, y):
      return (x & y, x | y, x * y)
    

    I can't prove it, though.

提交回复
热议问题