Salsa Developers' Blog
Python LinkedHashSet + LRU
Submitted Mon Feb 22 2010 16:47:00 GMT-0500 (EST)We're currently in the process of upgrading from Subversion to git, and one of the biggest challenges is preserving webDAV access for our 3rd party designers/developers. Last we checked, apache didn't have a git analogue to mod_dav_svn , so Jesse and Jason decided to implement one. The biggest difference between our git webDAV module and mod_dav_svn is that changes are batched rather than executed individually. Our primary reason is for performance, but we also didn't want to clog up the commit log with "webDAV autocommit" entries. One (small) challenge Jesse ran into was that he wanted a datastructure that:
- had the quick lookup of a hash map *AND*
- be sorted by a timestamp attribute
As is to be expected, python does not have built in implementations of every imaginable data structure, so he developed a little class functionally similar to Java's LinkedHashMap in that it maintains the insert order for each key, but that also appends a timestamp to each entry:
import time class TimeDict(dict):
def __init__(self,*args,**kwargs):
dict.__init__(self,*args,**kwargs)
self.orderedKeys = self.keys()
def __setitem__(self,key,value):
dict.__setitem__(self,key,(time.time(),value))
if key in self.orderedKeys:
self.orderedKeys.remove(key)
self.orderedKeys.append(key)
def __delitem__(self,key):
dict.__delitem__(self,key)
self.orderedKeys.remove(key)
def __getitem__(self,key):
return dict.__getitem__(self,key)[1]
def olderThan(self,timeout):
t = time.time()-timeout
result = {}
for key in self.orderedKeys:
timestamp,value = dict.__getitem__(self,key)
if timestamp < t:
result[key]=value
else:
break
return result
Sample Usage:
>>> from timeDict import TimeDict
>>> a = TimeDict()
>>> a['foo'] = 'bar'
>>> a['bar'] = 'baz'
>>> a.olderThan(10) # key/value pairs older than 10 seconds
{'foo': 'bar'}
>>> a.olderThan(10)
{'foo': 'bar', 'bar': 'baz'}
developers [at] salsalabs [dot] com
Comments
A simple question
ESL Assignment Writing Services
Latest Anime 2020
Soft Shell Heated Jacket
OtherWhatsapp
geometry game
Green Welly Stop
, promo codes, coupons, and clearance sales at Brand Discount.
Trying to find a reliable writing service?
Trying to find a reliable writing service?
Sociology homework help
Java homework help
Java homework help
whatsapp mod
Youtube TV Promo Code
British Leather Jackets
UMA Pakistan
UMA’s mission is to offer our Principals, Customer and all other interested parties with consistently high-level of services that exceeds their expectations and requirements.
EfroTech
Melon Patches
Maple Custom Tees
watch movies trailers in free
watch movies trailers in free
Argos Discount Code
Wayfair Discount Code
Scholarship
Scholarships Gov In 2019-2020
WWW National Scholarship Portal
NSP Online
National Portal Scholarship 2021
Scholarship 2021-2022
Scholarship 2021
NSP Login 2021
Scholarship Form 2021
National Portal
NSP 2021 2022
Scholarship
Scholarship
Scholarship
Scholarship Portal
N-Scholarship
NSP Portal
NSP Login
NSP Scholarship
Minority Scholarship
Post Matric Scholarship
NSP Home
Scholarship Gov In
Scholarship Portal
National Scholarship Portal 2021-22
NSP Scholarship 2021
National Scholarship Portal 2021
NSP Login 2021-22
Scholarships Gov In
Scholarship 2021-22
Sinkoth :-)
youtubers vs tiktokers boxing live
Logan Paul vs Floyd Mayweather Live Free
Olympics
nacy
Implants services in Lewisham
Mike
Mike
Thomas
Discount Voucher Code
Stephen
Robert
VoucherPro
FmWhatsApp
Boxing
Fight
McGregor Mma Fighting Live
McGregor vs Poirier Fight Streaming
Fury vs Joshua live stream
nacy
Escorts in islamabad
boxing
AJ vs Fury fight live
London Marathon organisers are "very optimistic" a record 50,000 runners are going to be ready to participate within the race when it's persisted 3 October for 2021 London Marathon Live Racing
This corner is allegedly named after a region character who had earned the moniker of Tarzan and just needed to present his kitchen garden inside the hills if the track’s designers named a close-by corner after him. 2021 f1 grand prix confirmed Francorchamps’s facilities will undergo renovations before its race next year, with updates to the infrastructure and therefore the circuit itself to satisfy required standards. Since 1985, Francorchamps has still remained a daily fixture in junior categories, meaning most drivers have had some experience of it.
WJC 2022
SportsDady - Latest Sports News and Events Information
https://www.sportsdady.com/
SportsDady - Latest Sports News and Events Information
movies
download
https://fineststar.in/black-adam-hindi-dubbed-download/
https://fineststar.in/kantara-hindi-dubbing-movie-download/
https://fineststar.in/download-godfather/
https://fineststar.in/black-panther-wakanda-forever-hindi/
website provide information about bollywood and Hollywood movie best reviews
hindi movie download
black adam hindi movie download
kantara movie download
download godfather
black panther wakanda fover movie download
website provide information about bollywood and Hollywood movie best reviews
forculnoc
Bodybuilding
hockey
Please login to post comments