1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 1996,2008 Oracle.  All rights reserved.
4#
5# $Id: hsearch.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $
6#
7# Historic Hsearch interface test.
8# Use the first 1000 entries from the dictionary.
9# Insert each with self as key and data; retrieve each.
10# After all are entered, retrieve all; compare output to original.
11# Then reopen the file, re-retrieve everything.
12# Finally, delete everything.
13proc hsearch { { nentries 1000 } } {
14	source ./include.tcl
15
16	puts "HSEARCH interfaces test: $nentries"
17
18	# Create the database and open the dictionary
19	set t1 $testdir/t1
20	set t2 $testdir/t2
21	set t3 $testdir/t3
22	cleanup $testdir NULL
23
24	error_check_good hcreate [berkdb hcreate $nentries] 0
25	set did [open $dict]
26	set count 0
27
28	puts "\tHSEARCH.a: put/get loop"
29	# Here is the loop where we put and get each key/data pair
30	while { [gets $did str] != -1 && $count < $nentries } {
31		set ret [berkdb hsearch $str $str enter]
32		error_check_good hsearch:enter $ret 0
33
34		set d [berkdb hsearch $str 0 find]
35		error_check_good hsearch:find $d $str
36		incr count
37	}
38	close $did
39
40	puts "\tHSEARCH.b: re-get loop"
41	set did [open $dict]
42	# Here is the loop where we retrieve each key
43	while { [gets $did str] != -1 && $count < $nentries } {
44		set d [berkdb hsearch $str 0 find]
45		error_check_good hsearch:find $d $str
46		incr count
47	}
48	close $did
49	error_check_good hdestroy [berkdb hdestroy] 0
50}
51