<commit_before>! Copyright (C) 2009 <NAME>
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data arrays assocs
destructors fry functors kernel locals sequences serialize
tokyo.alien.tcutil tokyo.utils vectors ;
IN: tokyo.assoc-functor

FUNCTOR: define-tokyo-assoc-api ( T N -- )

DBGET      IS ${T}get
DBPUT      IS ${T}put
DBOUT      IS ${T}out
DBDEL      IS ${T}del
DBRNUM     IS ${T}rnum
DBITERINIT IS ${T}iterinit
DBITERNEXT IS ${T}iternext
DBVANISH   IS ${T}vanish

DBKEYS DEFINES tokyo-${N}-keys

TYPE DEFINES-CLASS tokyo-${N}

WHERE

TUPLE: TYPE handle disposed ;

INSTANCE: TYPE assoc

M: TYPE dispose* [ DBDEL f ] change-handle drop ;

M: TYPE at* ( key db -- value/f ? )
    handle>> swap object>bytes dup length 0 int <ref>
    DBGET [ [ memory>object ] [ tcfree ] bi t ] [ f f ] if* ;

M: TYPE assoc-size ( db -- size ) handle>> DBRNUM ;

: DBKEYS ( db -- keys )
    [ assoc-size <vector> ] [ handle>> ] bi
    dup DBITERINIT drop 0 int <ref>
    [ 2dup DBITERNEXT dup ] [
        [ memory>object ] [ tcfree ] bi
        [ pick ] dip swap push
    ] while 3drop ;

M: TYPE >alist ( db -- alist )
    [ DBKEYS dup ] keep '[ dup _ at 2array ] map! drop ;

M: TYPE set-at ( value key db -- )
    handle>> swap rot [ object>bytes dup length ] bi@ DBPUT drop ;

M: TYPE delete-at ( key db -- )
    handle>> swap object>bytes dup length DBOUT drop ;

M: TYPE clear-assoc ( db -- ) handle>> DBVANISH drop ;

M: TYPE equal? assoc= ;

M: TYPE hashcode* assoc-hashcode ;

;FUNCTOR<commit_msg>tokyo.remotedb: remove stack effects.<commit_after>! Copyright (C) 2009 <NAME>
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data arrays assocs
destructors fry functors kernel locals sequences serialize
tokyo.alien.tcutil tokyo.utils vectors ;
IN: tokyo.assoc-functor

FUNCTOR: define-tokyo-assoc-api ( T N -- )

DBGET      IS ${T}get
DBPUT      IS ${T}put
DBOUT      IS ${T}out
DBDEL      IS ${T}del
DBRNUM     IS ${T}rnum
DBITERINIT IS ${T}iterinit
DBITERNEXT IS ${T}iternext
DBVANISH   IS ${T}vanish

DBKEYS DEFINES tokyo-${N}-keys

TYPE DEFINES-CLASS tokyo-${N}

WHERE

TUPLE: TYPE handle disposed ;

INSTANCE: TYPE assoc

M: TYPE dispose* [ DBDEL f ] change-handle drop ;

M: TYPE at*
    handle>> swap object>bytes dup length 0 int <ref>
    DBGET [ [ memory>object ] [ tcfree ] bi t ] [ f f ] if* ;

M: TYPE assoc-size handle>> DBRNUM ;

: DBKEYS ( db -- keys )
    [ assoc-size <vector> ] [ handle>> ] bi
    dup DBITERINIT drop 0 int <ref>
    [ 2dup DBITERNEXT dup ] [
        [ memory>object ] [ tcfree ] bi
        [ pick ] dip swap push
    ] while 3drop ;

M: TYPE >alist
    [ DBKEYS dup ] keep '[ dup _ at 2array ] map! drop ;

M: TYPE set-at
    handle>> swap rot [ object>bytes dup length ] bi@ DBPUT drop ;

M: TYPE delete-at
    handle>> swap object>bytes dup length DBOUT drop ;

M: TYPE clear-assoc handle>> DBVANISH drop ;

M: TYPE equal? assoc= ;

M: TYPE hashcode* assoc-hashcode ;

;FUNCTOR
{'fraction_non_alphanumeric': 0.12087912087912088, 'fraction_numerical': 0.005994005994005994, 'mean_word_length': 2.9788079470198676, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5518007', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1100, 'n_words': 363}