1// Index.h
2
3#ifndef INDEX_H
4#define INDEX_H
5
6#include <SupportDefs.h>
7
8#include "String.h"
9
10class AbstractIndexEntryIterator;
11class Entry;
12class IndexEntryIterator;
13class Node;
14class Volume;
15
16// Index
17class Index {
18public:
19	Index(Volume *volume, const char *name, uint32 type,
20		  bool fixedKeyLength, size_t keyLength = 0);
21	virtual ~Index();
22
23	status_t InitCheck() const;
24
25	Volume *GetVolume() const		{ return fVolume; }
26	void GetVolume(Volume *volume)	{ fVolume = volume; }
27
28	const char *GetName() const		{ return fName.GetString(); }
29	uint32 GetType() const			{ return fType; }
30	bool HasFixedKeyLength() const	{ return fFixedKeyLength; }
31	size_t GetKeyLength() const		{ return fKeyLength; }
32
33	virtual int32 CountEntries() const = 0;
34
35	bool GetIterator(IndexEntryIterator *iterator);
36	bool Find(const uint8 *key, size_t length,
37			  IndexEntryIterator *iterator);
38
39	// debugging
40	void Dump();
41
42protected:
43	virtual AbstractIndexEntryIterator *InternalGetIterator() = 0;
44	virtual AbstractIndexEntryIterator *InternalFind(const uint8 *key,
45													 size_t length) = 0;
46
47protected:
48	Volume		*fVolume;
49	status_t	fInitStatus;
50	String		fName;
51	uint32		fType;
52	size_t		fKeyLength;
53	bool		fFixedKeyLength;
54};
55
56// IndexEntryIterator
57class IndexEntryIterator {
58public:
59	IndexEntryIterator();
60	IndexEntryIterator(Index *index);
61	~IndexEntryIterator();
62
63	Entry *GetCurrent();
64	Entry *GetCurrent(uint8 *buffer, size_t *keyLength);
65	Entry *GetPrevious();
66	Entry *GetNext();
67	Entry *GetNext(uint8 *buffer, size_t *keyLength);
68
69	status_t Suspend();
70	status_t Resume();
71
72private:
73	void SetIterator(AbstractIndexEntryIterator *iterator);
74
75private:
76	friend class Index;
77
78	AbstractIndexEntryIterator	*fIterator;
79};
80
81#endif	// INDEX_H
82