c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef SQUAT_UIDLIST_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define SQUAT_UIDLIST_H
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenstruct squat_trie;
5889b12a55df32b93428b7fb52c06cfd749bee07Timo Sirainenstruct squat_uidlist_build_context;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenstruct squat_uidlist_rebuild_context;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenstruct squat_uidlist_file_header {
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen uint32_t indexid;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen uint32_t used_file_size;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen uint32_t block_list_offset;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen uint32_t count, link_count;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen};
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen/*
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen uidlist file:
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen struct uidlist_header;
1777c974563740daac427d3ef738903d8f6ad7d0Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen // size includes both prev_offset and uidlist
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen packed (size << 2) | packed_flags; // UIDLIST_PACKED_FLAG_*
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen [packed prev_offset;] // If UIDLIST_PACKED_FLAG_BEGINS_WITH_OFFSET is set
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen if (UIDLIST_PACKED_FLAG_BITMASK) {
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen packed base_uid; // first UID in uidlist
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen uint8_t bitmask[]; // first bit is base_uid+1
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen } else {
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen // FIXME: packed range
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen }
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen*/
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen#define UIDLIST_IS_SINGLETON(idx) \
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen (((idx) & 1) != 0 || (idx) < (0x100 << 1))
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenstruct squat_uidlist *squat_uidlist_init(struct squat_trie *trie);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenvoid squat_uidlist_deinit(struct squat_uidlist *uidlist);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
5889b12a55df32b93428b7fb52c06cfd749bee07Timo Sirainenint squat_uidlist_refresh(struct squat_uidlist *uidlist);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen
5889b12a55df32b93428b7fb52c06cfd749bee07Timo Sirainenint squat_uidlist_build_init(struct squat_uidlist *uidlist,
5889b12a55df32b93428b7fb52c06cfd749bee07Timo Sirainen struct squat_uidlist_build_context **ctx_r);
5889b12a55df32b93428b7fb52c06cfd749bee07Timo Sirainenuint32_t squat_uidlist_build_add_uid(struct squat_uidlist_build_context *ctx,
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen uint32_t uid_list_idx, uint32_t uid);
5889b12a55df32b93428b7fb52c06cfd749bee07Timo Sirainenvoid squat_uidlist_build_flush(struct squat_uidlist_build_context *ctx);
5889b12a55df32b93428b7fb52c06cfd749bee07Timo Sirainenint squat_uidlist_build_finish(struct squat_uidlist_build_context *ctx);
5889b12a55df32b93428b7fb52c06cfd749bee07Timo Sirainenvoid squat_uidlist_build_deinit(struct squat_uidlist_build_context **ctx);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen
5889b12a55df32b93428b7fb52c06cfd749bee07Timo Sirainenint squat_uidlist_rebuild_init(struct squat_uidlist_build_context *build_ctx,
5889b12a55df32b93428b7fb52c06cfd749bee07Timo Sirainen bool compress,
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen struct squat_uidlist_rebuild_context **ctx_r);
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainenuint32_t squat_uidlist_rebuild_next(struct squat_uidlist_rebuild_context *ctx,
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen const ARRAY_TYPE(uint32_t) *uids);
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainenuint32_t squat_uidlist_rebuild_nextu(struct squat_uidlist_rebuild_context *ctx,
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen const ARRAY_TYPE(seq_range) *uids);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenint squat_uidlist_rebuild_finish(struct squat_uidlist_rebuild_context *ctx,
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen bool cancel);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenint squat_uidlist_get(struct squat_uidlist *uidlist, uint32_t uid_list_idx,
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen ARRAY_TYPE(uint32_t) *uids);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenuint32_t squat_uidlist_singleton_last_uid(uint32_t uid_list_idx);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenint squat_uidlist_get_seqrange(struct squat_uidlist *uidlist,
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen uint32_t uid_list_idx,
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen ARRAY_TYPE(seq_range) *seq_range_arr);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenint squat_uidlist_filter(struct squat_uidlist *uidlist, uint32_t uid_list_idx,
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen ARRAY_TYPE(seq_range) *uids);
a3fc085ffb855d7b5e1dba611254a0db3f8c429dTimo Sirainen
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenvoid squat_uidlist_delete(struct squat_uidlist *uidlist);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainensize_t squat_uidlist_mem_used(struct squat_uidlist *uidlist,
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen unsigned int *count_r);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen#endif