def crc32(data, crc=0): ''' Calculates the (unsigned) 32 bit cyclic redundancy check of a byte sequence:: >>> crc = crc32('Hello ') >>> crc = crc32('world!', crc) >>> print hex(crc) 0x1b851995 ''' return _crc32(data, crc) & 0xffffffff
def crc32(data): """Python version idempotent""" return _crc32(data.encode()) & 0xFFFFFFFF
def __init__(self, s=''): self.value = _crc32(s)
def update(self, s): self.value = _crc32(s, self.value)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os import sys import sqlite3 from zlib import crc32 as _crc32 from sqlitecache import SqliteCache from zhutil import calctxtstat from config import * crc32 = lambda s: _crc32(s.encode('utf-8')) & 0xffffffff cache = SqliteCache(DB_zhccache, DB_zhccache_maxlen) if os.path.isfile(DB_testsent): os.unlink(DB_testsent) #db = sqlite3.connect(DB_testsent) #cur = db.cursor() # else: db = sqlite3.connect(DB_testsent) cur = db.cursor() cur.execute( "CREATE TABLE sentences (id INTEGER PRIMARY KEY, sent TEXT, type INTEGER)") db.commit() cf = open(os.path.join(OS_DATA, "zhc.txt")).read().split('\n') mf = open(os.path.join(OS_DATA, "zhm.txt")).read().split('\n') count = 0 ccount = 0 mcount = 0
def crc32(data): """Python version idempotent""" return _crc32(data) & 0xFFFFFFFF
def hash32(text: StrBytes, init: int = 0) -> int: return _crc32(to_bytes(text), unsigned_I(init))
def crc32(data): """Python version idempotent""" return _crc32(data) & 0xffffffff