I need to simulate a poker-table-like queue where the users take their positions based on the first available seat. I've seen it done with lists, but I have solved it using bitwise ops.
def add_user_to_table(max_users=8):
global tbl
# simulate the first position: 00000001
pos = 1
# iterate through all positions. break once found empty position
for i in range (0, max_users):
if not (tbl & pos):
# found an empty position...
# return position, break, etc...
else:
# shift the bit 1 position left to check the next position
# so after the 1st iteration pos will be 00000010
pos = pos << 1
# main. Define a table with some users seated
# a table with seats 1, 3, 4, 6 taken
tbl = int('00101101', 2)
# now place the user on the first available seat (second seat in this example)
add_user_to_table()
In terms of performance (I will need thousands of tables with dozens of users), will this be the fastest and most efficient way?
Would lists/queues/deques etc. out-perform this method?