File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -177,14 +177,37 @@ Batch reads allow you to read a batch of data sequentially stored.
177177
178178Here is an example of iterating all the records in a string database.
179179
180+ Example 1 - Using Indicies
180181```cpp
181182ashdb::AshDB<std::string> stringdb("stringdb");
182183assert(db.opened() == false);
183184assert(db.open() == ashdb::OpenStatus::OK);
184185for (auto i = 0u; i < db.size(); ++i)
185186{
186187 std::string str = db.read(i);
187- std::cout << i << ':' << str << '\n';
188+ std::cout << str << '\n';
189+ }
190+ ```
191+
192+ Example 2 - Using Ranges
193+ ``` cpp
194+ ashdb::AshDB<std::string> stringdb ("stringdb");
195+ assert(db.opened() == false);
196+ assert(db.open() == ashdb::OpenStatus::OK);
197+ for (auto str : db)
198+ {
199+ std::cout << str << '\n';
200+ }
201+ ```
202+
203+ Example 3 - Using Iterators
204+ ```cpp
205+ ashdb::AshDB<std::string> stringdb("stringdb");
206+ assert(db.opened() == false);
207+ assert(db.open() == ashdb::OpenStatus::OK);
208+ for (auto it = db.begin(); it != db.end(); ++it)
209+ {
210+ std::cout << *it << '\n';
188211}
189212```
190213
Original file line number Diff line number Diff line change @@ -508,9 +508,9 @@ BOOST_AUTO_TEST_CASE(db_size)
508508 BOOST_TEST (db.databaseSize () > 210 );
509509}
510510
511- BOOST_AUTO_TEST_CASE (iterator )
511+ BOOST_AUTO_TEST_CASE (iterator1 )
512512{
513- auto tempFolder = ashdb::test::tempFolder (" iterator " );
513+ auto tempFolder = ashdb::test::tempFolder (" iterator1 " );
514514
515515 ashdb::Options options;
516516 options.filesize_max = 1024 ;
@@ -534,4 +534,30 @@ BOOST_AUTO_TEST_CASE(iterator)
534534 }
535535}
536536
537+ BOOST_AUTO_TEST_CASE (iterator2)
538+ {
539+ auto tempFolder = ashdb::test::tempFolder (" iterator2" );
540+
541+ ashdb::Options options;
542+ options.filesize_max = 1024 ;
543+
544+ ashdb::AshDB<int > db{tempFolder, options};
545+ BOOST_TEST (db.open () == ashdb::OpenStatus::OK );
546+
547+ ashdb::AshDB<int >::Batch batch;
548+
549+ // create the initial 100 records
550+ for (auto i = 0u ; i < 100 ; ++i)
551+ {
552+ batch.push_back (i * 10 );
553+ }
554+ BOOST_TEST (db.write (batch) == ashdb::WriteStatus::OK );
555+
556+ int x = 0 ;
557+ for (auto it = db.begin (); it != db.end (); ++it)
558+ {
559+ BOOST_TEST (*it == (x++ * 10 ));
560+ }
561+ }
562+
537563BOOST_AUTO_TEST_SUITE_END ()
You can’t perform that action at this time.
0 commit comments