def __init__(self, prefix, fields): ''' Constructor ''' AbstractKey.__init__(self, prefix, fields) Rediston.__init__(self) self.hasher = pyhash.fnv1a_64()
def __init__(self, capacity=100000, error_rate=0.001): """ BloomFilter is a probabilistic datastructure which are helpful in approximate membership queries. They only suffer from type 1 false positive errors and the error rate can be tuned to specific requirements. """ self.total_size = int(round(-capacity * math.log(error_rate) / (math.log(2) ** 2))) self.k = int(round(self.total_size * math.log(2) / capacity)) self.size = int(round(self.total_size / self.k)) self.bitarrays = [] self.h1 = pyhash.fnv1a_64() self.h2 = pyhash.murmur2_x86_64b() for i in xrange(self.k): b = bitarray(self.size, endian='little') b.setall(False) self.bitarrays.append(b)
def __init__(self, capacity=100000, error_rate=0.001): """ BloomFilter is a probabilistic datastructure which are helpful in approximate membership queries. They only suffer from type 1 false positive errors and the error rate can be tuned to specific requirements. """ self.total_size = int( round(-capacity * math.log(error_rate) / (math.log(2)**2))) self.k = int(round(self.total_size * math.log(2) / capacity)) self.size = int(round(self.total_size / self.k)) self.bitarrays = [] self.h1 = pyhash.fnv1a_64() self.h2 = pyhash.murmur2_x86_64b() for i in xrange(self.k): b = bitarray(self.size, endian='little') b.setall(False) self.bitarrays.append(b)
import array import functools import itertools import mmap import struct import pyhash # FNV1a with the same seed as Go. chd_hash = functools.partial(pyhash.fnv1a_64(), seed=14695981039346656037) class CHD(object): def __init__(self, filename): len = struct.Struct('<L') with open(filename) as fd: self._mmap = mmap.mmap(fd.fileno(), 0, prot=mmap.PROT_READ) rl = len.unpack_from(self._mmap[:4]) self._r = array.array('<L') def __getitem__(self, key): r0 = self._r[0] h = chd_hash(key) ^ r0 i = h % len(self._indices) ri = self._indices[i] r = self._r[ri] ti = (h ^ r) % len(self._keys) if self._keys[ti] != key: raise KeyError(key, self._keys[ti]) return self._values[ti]
#https://code.google.com/p/pyfasthash/ h_fnv1_32 = pyhash.fnv1_32() def fnv1_32(req): return h_fnv1_32(str(req)) h_lookup3 = pyhash.lookup3_big() def lookup3(req): return h_lookup3(str(req)) h_super_fast_hash = pyhash.super_fast_hash() def super_fast_hash(req): return h_super_fast_hash(str(req)) h_murmur2_x64_64a = pyhash.murmur2_x64_64a() def murmur2_x64_64a(req): return h_murmur2_x64_64a(str(req)) h_murmur3_32 = pyhash.murmur3_32() def murmur3_32(req): return h_murmur3_32(str(req)) h_fnv1a_64 = pyhash.fnv1a_64() def fnv1a_64(req): return h_fnv1a_64(str(req))
from Functions.config import getConfig from Models.agency import Agency from Models.route import Route from Models.stop import Stop from Models.stop_times import StopTime from Models.trip import Trip from Models.calendar import Calendar from Models.calendar_date import CalendarDate from Models.transport_type_image import TransportTypeImage from Models.stop_time_text import StopTimeText import sqlalchemy import pyhash logger = logging.getLogger(__name__) hasher = pyhash.fnv1a_64() lock = threading.Lock() try: DATABASE_URI = 'postgres+psycopg2://' + str(getConfig('postgres')) except KeyError: DATABASE_URI = 'postgres+psycopg2://postgres:password@localhost:5432/postgres' from sqlalchemy import create_engine, and_, or_, func, literal_column, Text from sqlalchemy.orm import sessionmaker engine = create_engine(DATABASE_URI, executemany_mode='values') Session = sessionmaker(bind=engine, autoflush=False, autocommit=False, expire_on_commit=True)