From f3393cf57c5677db3a7767b3b079d65d5ee8f4cd Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 13 Sep 2014 17:29:58 +0200 Subject: [PATCH] * Improve interface for PointerHash --- spacy/_hashing.pxd | 6 +++--- spacy/lang.pxd | 2 +- spacy/lang.pyx | 18 +++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spacy/_hashing.pxd b/spacy/_hashing.pxd index f4c4f5b43..2255855e3 100644 --- a/spacy/_hashing.pxd +++ b/spacy/_hashing.pxd @@ -1,7 +1,7 @@ from libc.stdint cimport uint64_t ctypedef uint64_t key_t -ctypedef size_t val_t +ctypedef void* val_t cdef struct Cell: @@ -15,6 +15,6 @@ cdef class PointerHash: cdef Cell* _last cdef Cell* cells - cdef val_t lookup(self, key_t key) - cdef void insert(self, key_t key, val_t value) except * + cdef val_t get(self, key_t key) + cdef void set(self, key_t key, val_t value) except * cdef void resize(self, size_t new_size) except * diff --git a/spacy/lang.pxd b/spacy/lang.pxd index 1f61d0e95..6503002e4 100644 --- a/spacy/lang.pxd +++ b/spacy/lang.pxd @@ -25,7 +25,7 @@ cdef class Lexicon: cpdef readonly size_t size cpdef Lexeme lookup(self, unicode string) - cdef size_t get(self, String* s) + cdef LexemeC* get(self, String* s) cdef PointerHash _dict diff --git a/spacy/lang.pyx b/spacy/lang.pyx index 50f421005..2d5654071 100644 --- a/spacy/lang.pyx +++ b/spacy/lang.pyx @@ -122,7 +122,6 @@ cdef class Language: cdef int split cdef int remaining = string.n cdef String prefix - cdef Cell* tmp_cell while remaining >= 1: split = self._split_one(string.chars, string.n) remaining -= split @@ -194,10 +193,11 @@ cdef class Lexicon: self._dict.set(string.key, lexeme) self.size += 1 - cdef size_t get(self, String* string): - cdef LexemeC* lex_addr = self._dict.get(string.key) - if lex_addr != NULL: - return lex_addr + cdef LexemeC* get(self, String* string): + cdef LexemeC* lexeme + lexeme = self._dict.get(string.key) + if lexeme != NULL: + return lexeme cdef unicode uni_string = string.chars[:string.n] views = [string_view(uni_string, 0.0, 0, {}, {}) @@ -207,10 +207,10 @@ cdef class Lexicon: if flag_feature(uni_string, 0.0, {}, {}): flags.add(i) - cdef LexemeC* lexeme = lexeme_init(uni_string, 0, 0, views, flags) + lexeme = lexeme_init(uni_string, 0, 0, views, flags) self._dict.set(string.key, lexeme) self.size += 1 - return lexeme + return lexeme cpdef Lexeme lookup(self, unicode uni_string): """Retrieve (or create, if not found) a Lexeme for a string, and return it. @@ -223,8 +223,8 @@ cdef class Lexicon: """ cdef String string string_from_unicode(&string, uni_string) - cdef size_t lexeme = self.get(&string) - return Lexeme(lexeme) + cdef LexemeC* lexeme = self.get(&string) + return Lexeme(lexeme) cdef void string_from_unicode(String* s, unicode uni):