⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 berkeleydb.pod.p

📁 BerkeleyDB源码
💻 P
📖 第 1 页 / 共 4 页
字号:
hashing packages like DBM, NDBM, ODBM, GDBM, and SDBM. Remember though,the files created using B<BerkeleyDB::Hash> are not compatible with anyof the other packages mentioned.A default hashing algorithm, which will be adequate for most applications,is built into BerkeleyDB. If you do need to use your own hashing algorithmit is possible to write your own in Perl and have B<BerkeleyDB> useit instead.=item B<BerkeleyDB::Btree>The Btree format allows arbitrary key/value pairs to be stored in aB+tree.As with the B<BerkeleyDB::Hash> format, it is possible to provide auser defined Perl routine to perform the comparison of keys. By default,though, the keys are stored in lexical order.=item B<BerkeleyDB::Recno>TODO.=item B<BerkeleyDB::Queue>TODO.=item B<BerkeleyDB::Unknown>This isn't a database format at all. It is used when you want to open anexisting Berkeley DB database without having to know what type is it. =backEach of the database formats described above is accessed via acorresponding B<BerkeleyDB> class. These will be described in turn inthe next sections.=head1 BerkeleyDB::HashEquivalent to calling B<db_open> with type B<DB_HASH> in Berkeley DB 2.x andcalling B<db_create> followed by B<DB-E<gt>open> with type B<DB_HASH> inBerkeley DB 3.x or greater. Two forms of constructor are supported:    $db = new BerkeleyDB::Hash                [ -Filename      => "filename", ]                [ -Subname       => "sub-database name", ]                [ -Flags         => flags,]                [ -Property      => flags,]                [ -Mode          => number,]                [ -Cachesize     => number,]                [ -Lorder        => number,]                [ -Pagesize      => number,]                [ -Env           => $env,]                [ -Txn           => $txn,]                [ -Encrypt       => { Password => "string",	                              Flags    => number }, ],                # BerkeleyDB::Hash specific                [ -Ffactor       => number,]                [ -Nelem         => number,]                [ -Hash          => code reference,]                [ -DupCompare    => code reference,]and this    [$db =] tie %hash, 'BerkeleyDB::Hash',                 [ -Filename      => "filename", ]                [ -Subname       => "sub-database name", ]                [ -Flags         => flags,]                [ -Property      => flags,]                [ -Mode          => number,]                [ -Cachesize     => number,]                [ -Lorder        => number,]                [ -Pagesize      => number,]                [ -Env           => $env,]                [ -Txn           => $txn,]                [ -Encrypt       => { Password => "string",	                              Flags    => number }, ],                # BerkeleyDB::Hash specific                [ -Ffactor       => number,]                [ -Nelem         => number,]                [ -Hash          => code reference,]                [ -DupCompare    => code reference,]When the "tie" interface is used, reading from and writing to the databaseis achieved via the tied hash. In this case the database operates likea Perl associative array that happens to be stored on disk.In addition to the high-level tied hash interface, it is possible tomake use of the underlying methods provided by Berkeley DB=head2 OptionsIn addition to the standard set of options (see L<COMMON OPTIONS>)B<BerkeleyDB::Hash> supports these options:=over 5=item -PropertyUsed to specify extra flags when opening a database. The followingflags may be specified by bitwise OR'ing together one or more of thefollowing values:B<DB_DUP>When creating a new database, this flag enables the storing of duplicatekeys in the database. If B<DB_DUPSORT> is not specified as well, theduplicates are stored in the order they are created in the database.B<DB_DUPSORT>Enables the sorting of duplicate keys in the database. Ignored ifB<DB_DUP> isn't also specified.=item -Ffactor=item -NelemSee the Berkeley DB documentation for details of these options.=item -HashAllows you to provide a user defined hash function. If not specified, a default hash function is used. Here is a template for a user-definedhash function    sub hash    {        my ($data) = shift ;        ...        # return the hash value for $data	return $hash ;    }    tie %h, "BerkeleyDB::Hash",         -Filename => $filename,     	-Hash     => \&hash,	...See L<""> for an example.=item -DupCompareUsed in conjunction with the B<DB_DUPOSRT> flag.     sub compare    {	my ($key, $key2) = @_ ;        ...        # return  0 if $key1 eq $key2        #        -1 if $key1 lt $key2        #         1 if $key1 gt $key2        return (-1 , 0 or 1) ;    }    tie %h, "BerkeleyDB::Hash",         -Filename   => $filename, 	-Property   => DB_DUP|DB_DUPSORT,    	-DupCompare => \&compare,	...=back=head2 MethodsB<BerkeleyDB::Hash> only supports the standard database methods.See L<COMMON DATABASE METHODS>.=head2 A Simple Tied Hash Example## simpleHashhere is the output:    Banana Exists        orange -> orange    tomato -> red    banana -> yellowNote that the like ordinary associative arrays, the order of the keysretrieved from a Hash database are in an apparently random order.=head2 Another Simple Hash ExampleDo the same as the previous example but not using tie.## simpleHash2=head2 Duplicate keysThe code below is a variation on the examples above. This time the hash hasbeen inverted. The key this time is colour and the value is the fruit name.The B<DB_DUP> flag has been specified to allow duplicates.##dupHashhere is the output:    orange -> orange    yellow -> banana    red -> apple    red -> tomato    green -> banana    green -> apple=head2 Sorting Duplicate KeysIn the previous example, when there were duplicate keys, the values aresorted in the order they are stored in. The code below isidentical to the previous example except the B<DB_DUPSORT> flag isspecified.##dupSortHashNotice that in the output below the duplicate values are sorted.    orange -> orange    yellow -> banana    red -> apple    red -> tomato    green -> apple    green -> banana=head2 Custom Sorting Duplicate KeysAnother variation TODO=head2 Changing the hashTODO=head2 Using db_statTODO=head1 BerkeleyDB::BtreeEquivalent to calling B<db_open> with type B<DB_BTREE> in Berkeley DB 2.x andcalling B<db_create> followed by B<DB-E<gt>open> with type B<DB_BTREE> inBerkeley DB 3.x or greater. Two forms of constructor are supported:    $db = new BerkeleyDB::Btree                [ -Filename      => "filename", ]                [ -Subname       => "sub-database name", ]                [ -Flags         => flags,]                [ -Property      => flags,]                [ -Mode          => number,]                [ -Cachesize     => number,]                [ -Lorder        => number,]                [ -Pagesize      => number,]                [ -Env           => $env,]                [ -Txn           => $txn,]                [ -Encrypt       => { Password => "string",	                              Flags    => number }, ],                # BerkeleyDB::Btree specific                [ -Minkey        => number,]                [ -Compare       => code reference,]                [ -DupCompare    => code reference,]                [ -Prefix        => code reference,]and this    [$db =] tie %hash, 'BerkeleyDB::Btree',                 [ -Filename      => "filename", ]                [ -Subname       => "sub-database name", ]                [ -Flags         => flags,]                [ -Property      => flags,]                [ -Mode          => number,]                [ -Cachesize     => number,]                [ -Lorder        => number,]                [ -Pagesize      => number,]                [ -Env           => $env,]                [ -Txn           => $txn,]                [ -Encrypt       => { Password => "string",	                              Flags    => number }, ],                # BerkeleyDB::Btree specific                [ -Minkey        => number,]                [ -Compare       => code reference,]                [ -DupCompare    => code reference,]                [ -Prefix        => code reference,]=head2 OptionsIn addition to the standard set of options (see L<COMMON OPTIONS>)B<BerkeleyDB::Btree> supports these options:=over 5=item -PropertyUsed to specify extra flags when opening a database. The followingflags may be specified by bitwise OR'ing together one or more of thefollowing values:B<DB_DUP>When creating a new database, this flag enables the storing of duplicatekeys in the database. If B<DB_DUPSORT> is not specified as well, theduplicates are stored in the order they are created in the database.B<DB_DUPSORT>Enables the sorting of duplicate keys in the database. Ignored ifB<DB_DUP> isn't also specified.=item MinkeyTODO=item CompareAllow you to override the default sort order used in the database. SeeL<"Changing the sort order"> for an example.    sub compare    {	my ($key, $key2) = @_ ;        ...        # return  0 if $key1 eq $key2        #        -1 if $key1 lt $key2        #         1 if $key1 gt $key2        return (-1 , 0 or 1) ;    }    tie %h, "BerkeleyDB::Hash",         -Filename   => $filename,     	-Compare    => \&compare,	...=item Prefix    sub prefix    {	my ($key, $key2) = @_ ;        ...        # return number of bytes of $key2 which are         # necessary to determine that it is greater than $key1        return $bytes ;    }    tie %h, "BerkeleyDB::Hash",         -Filename   => $filename,     	-Prefix     => \&prefix,	...=item DupCompare    sub compare    {	my ($key, $key2) = @_ ;        ...        # return  0 if $key1 eq $key2        #        -1 if $key1 lt $key2        #         1 if $key1 gt $key2        return (-1 , 0 or 1) ;    }    tie %h, "BerkeleyDB::Hash",         -Filename   => $filename,     	-DupCompare => \&compare,	...=back=head2 MethodsB<BerkeleyDB::Btree> supports the following database methods.See also L<COMMON DATABASE METHODS>.All the methods below return 0 to indicate success.=over 5=item $status = $db->db_key_range($key, $less, $equal, $greater [, $flags])Given a key, C<$key>, this method returns the proportion of keys less than C<$key> in C<$less>, the proportion equal to C<$key> in C<$equal> and theproportion greater than C<$key> in C<$greater>.The proportion is returned as a double in the range 0.0 to 1.0.=back=head2 A Simple Btree ExampleThe code below is a simple example of using a btree database.## btreeSimpleHere is the output from the code above. The keys have been sorted usingBerkeley DB's default sorting algorithm.    Smith    Wall    mouse=head2 Changing the sort orderIt is possible to supply your own sorting algorithm if the one that BerkeleyDB used isn't suitable. The code below is identical to the previous exampleexcept for the case insensitive compare function.## btreeSortOrderHere is the output from the code above.    mouse    Smith    Wall

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -