Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / html / python / lib / bsddb-objects.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="prev" href="module-bsddb.html" />
<link rel="parent" href="module-bsddb.html" />
<link rel="next" href="module-dumbdbm.html" />
<meta name='aesop' content='information' />
<title>7.13.1 Hash, BTree and Record Objects </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="7.13 bsddb "
href="module-bsddb.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="7.13 bsddb "
href="module-bsddb.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="7.14 dumbdbm "
href="module-dumbdbm.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-bsddb.html">7.13 bsddb </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-bsddb.html">7.13 bsddb </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-dumbdbm.html">7.14 dumbdbm </A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION0091310000000000000000"></A><A NAME="bsddb-objects"></A>
<BR>
7.13.1 Hash, BTree and Record Objects
</H2>
<P>
Once instantiated, hash, btree and record objects support
the same methods as dictionaries. In addition, they support
the methods listed below.
<span class="versionnote">Changed in version 2.3.1:
Added dictionary methods.</span>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2800' xml:id='l2h-2800' class="method">close</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Close the underlying file. The object can no longer be accessed. Since
there is no open <tt class="method">open</tt> method for these objects, to open the file
again a new <tt class="module">bsddb</tt> module open function must be called.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2801' xml:id='l2h-2801' class="method">keys</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Return the list of keys contained in the DB file. The order of the list is
unspecified and should not be relied on. In particular, the order of the
list returned is different for different file formats.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2802' xml:id='l2h-2802' class="method">has_key</tt></b>(</nobr></td>
<td><var>key</var>)</td></tr></table></dt>
<dd>
Return <code>1</code> if the DB file contains the argument as a key.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2803' xml:id='l2h-2803' class="method">set_location</tt></b>(</nobr></td>
<td><var>key</var>)</td></tr></table></dt>
<dd>
Set the cursor to the item indicated by <var>key</var> and return a tuple
containing the key and its value. For binary tree databases (opened
using <tt class="function">btopen()</tt>), if <var>key</var> does not actually exist in
the database, the cursor will point to the next item in sorted order
and return that key and value. For other databases,
<tt class="exception">KeyError</tt> will be raised if <var>key</var> is not found in the
database.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2804' xml:id='l2h-2804' class="method">first</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Set the cursor to the first item in the DB file and return it. The order of
keys in the file is unspecified, except in the case of B-Tree databases.
This method raises <tt class="exception">bsddb.error</tt> if the database is empty.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2805' xml:id='l2h-2805' class="method">next</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Set the cursor to the next item in the DB file and return it. The order of
keys in the file is unspecified, except in the case of B-Tree databases.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2806' xml:id='l2h-2806' class="method">previous</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Set the cursor to the previous item in the DB file and return it. The
order of keys in the file is unspecified, except in the case of B-Tree
databases. This is not supported on hashtable databases (those opened
with <tt class="function">hashopen()</tt>).
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2807' xml:id='l2h-2807' class="method">last</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Set the cursor to the last item in the DB file and return it. The
order of keys in the file is unspecified. This is not supported on
hashtable databases (those opened with <tt class="function">hashopen()</tt>).
This method raises <tt class="exception">bsddb.error</tt> if the database is empty.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2808' xml:id='l2h-2808' class="method">sync</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Synchronize the database on disk.
</dl>
<P>
Example:
<P>
<div class="verbatim"><pre>
&gt;&gt;&gt; import bsddb
&gt;&gt;&gt; db = bsddb.btopen('/tmp/spam.db', 'c')
&gt;&gt;&gt; for i in range(10): db['%d'%i] = '%d'% (i*i)
...
&gt;&gt;&gt; db['3']
'9'
&gt;&gt;&gt; db.keys()
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
&gt;&gt;&gt; db.first()
('0', '0')
&gt;&gt;&gt; db.next()
('1', '1')
&gt;&gt;&gt; db.last()
('9', '81')
&gt;&gt;&gt; db.set_location('2')
('2', '4')
&gt;&gt;&gt; db.previous()
('1', '1')
&gt;&gt;&gt; for k, v in db.iteritems():
... print k, v
0 0
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
&gt;&gt;&gt; '8' in db
True
&gt;&gt;&gt; db.sync()
0
</pre></div>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="7.13 bsddb "
href="module-bsddb.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="7.13 bsddb "
href="module-bsddb.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="7.14 dumbdbm "
href="module-dumbdbm.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-bsddb.html">7.13 bsddb </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-bsddb.html">7.13 bsddb </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-dumbdbm.html">7.14 dumbdbm </A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>