Binary Search Tree

Chris Goffinet goffinet at yahoo-inc.com
Fri Sep 7 22:11:33 UTC 2007


Sure thing.

I am not sure if a binary tree could help the situation, was wondering  
if it could and how to implement if possible. Scenario:

1) User A visits website 1 time within hour (1). Object should only be  
created 1 time for the hour (we did this based on simple counter  
system and the website id).
2) User B visits website 1 time within hour (1). Object created.
3) User A visits website 1 time within hour (2). Object created.
4) User B visited website 1 time within hour (2). Object created.
5) User C visited website 1 time within hour (2). Object created.

The list should only show last 3 visitors to the site (unique) at any  
one time.  Last object being first:
   - User C
   - User B
   - User A

There is a possibility that a site could have no traffic for hours,  
and a user visits it each hour, so the list could have a user multiple  
times (spread by hour) since were only limiting it by the hour and we  
do want it to be unique. So what I am wondering is, how could we  
potentially get around this issue by avoiding locks? We thought about  
just storing an array for a site of last 10 users, then using array  
push/pop methods on it and use a lock method. But wouldn't a lock  
potentially delay the script executing until the lock is available  
(slowing down the execution time) ?

-Chris


On Sep 7, 2007, at 2:55 PM, dormando wrote:

>
>> In this case we would only just want to show User A one time  
>> especially since its a list of user activity. We can't store a hash  
>> and just push/pop because of race conditions (our first thought).  
>> If anyone has any ideas, I'd really appreciate it!
>
> I don't follow :( Could you try explaining what the problem is in  
> more detail, and how a binary tree setup would be better than a one  
> time lock?
>
> I don't really see the above example being a problem even if there  
> is a race condition.
>
> -Dormando

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20070907/df383330/attachment-0001.html


More information about the memcached mailing list