mail-hash.h revision 6680ef2694a8198ecae01e64363f35793fbcfd61
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen#ifndef __MAIL_HASH_H
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen#define __MAIL_HASH_H
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
345648b341f228bd7f0b89f8aa3ecb9c470d817eTimo Sirainentypedef struct _MailHashHeader MailHashHeader;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainentypedef struct _MailHashRecord MailHashRecord;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenstruct _MailHashHeader {
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen unsigned int indexid;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen unsigned int updateid;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen unsigned int used_records;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen unsigned int alignment;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen};
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenstruct _MailHashRecord {
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen unsigned int uid;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen uoff_t position;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen};
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen/* Open or create a hash file for index. If the hash needs to be created,
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen it's also immediately built from the given index. */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenint mail_hash_create(MailIndex *index);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenint mail_hash_open_or_create(MailIndex *index);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenvoid mail_hash_free(MailHash *hash);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen/* Synchronize the hash file with memory map */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenint mail_hash_sync_file(MailHash *hash);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen/* Rebuild hash from index and reset the FLAG_REBUILD_HASH in header.
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen The index must have an exclusive lock before this function is called. */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenint mail_hash_rebuild(MailHash *hash);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen/* Returns position in index file to given UID, or 0 if not found. */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenuoff_t mail_hash_lookup_uid(MailHash *hash, unsigned int uid);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen/* Update hash file. If pos is 0, the record is deleted. This call may
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen rebuild the hash if it's too full. */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenvoid mail_hash_update(MailHash *hash, unsigned int uid, uoff_t pos);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen#endif
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen