162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * tools/testing/selftests/kvm/include/sparsebit.h 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2018, Google LLC. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Header file that describes API to the sparsebit library. 862306a36Sopenharmony_ci * This library provides a memory efficient means of storing 962306a36Sopenharmony_ci * the settings of bits indexed via a uint64_t. Memory usage 1062306a36Sopenharmony_ci * is reasonable, significantly less than (2^64 / 8) bytes, as 1162306a36Sopenharmony_ci * long as bits that are mostly set or mostly cleared are close 1262306a36Sopenharmony_ci * to each other. This library is efficient in memory usage 1362306a36Sopenharmony_ci * even in the case where most bits are set. 1462306a36Sopenharmony_ci */ 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#ifndef SELFTEST_KVM_SPARSEBIT_H 1762306a36Sopenharmony_ci#define SELFTEST_KVM_SPARSEBIT_H 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#include <stdbool.h> 2062306a36Sopenharmony_ci#include <stdint.h> 2162306a36Sopenharmony_ci#include <stdio.h> 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#ifdef __cplusplus 2462306a36Sopenharmony_ciextern "C" { 2562306a36Sopenharmony_ci#endif 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_cistruct sparsebit; 2862306a36Sopenharmony_citypedef uint64_t sparsebit_idx_t; 2962306a36Sopenharmony_citypedef uint64_t sparsebit_num_t; 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_cistruct sparsebit *sparsebit_alloc(void); 3262306a36Sopenharmony_civoid sparsebit_free(struct sparsebit **sbitp); 3362306a36Sopenharmony_civoid sparsebit_copy(struct sparsebit *dstp, struct sparsebit *src); 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_cibool sparsebit_is_set(struct sparsebit *sbit, sparsebit_idx_t idx); 3662306a36Sopenharmony_cibool sparsebit_is_set_num(struct sparsebit *sbit, 3762306a36Sopenharmony_ci sparsebit_idx_t idx, sparsebit_num_t num); 3862306a36Sopenharmony_cibool sparsebit_is_clear(struct sparsebit *sbit, sparsebit_idx_t idx); 3962306a36Sopenharmony_cibool sparsebit_is_clear_num(struct sparsebit *sbit, 4062306a36Sopenharmony_ci sparsebit_idx_t idx, sparsebit_num_t num); 4162306a36Sopenharmony_cisparsebit_num_t sparsebit_num_set(struct sparsebit *sbit); 4262306a36Sopenharmony_cibool sparsebit_any_set(struct sparsebit *sbit); 4362306a36Sopenharmony_cibool sparsebit_any_clear(struct sparsebit *sbit); 4462306a36Sopenharmony_cibool sparsebit_all_set(struct sparsebit *sbit); 4562306a36Sopenharmony_cibool sparsebit_all_clear(struct sparsebit *sbit); 4662306a36Sopenharmony_cisparsebit_idx_t sparsebit_first_set(struct sparsebit *sbit); 4762306a36Sopenharmony_cisparsebit_idx_t sparsebit_first_clear(struct sparsebit *sbit); 4862306a36Sopenharmony_cisparsebit_idx_t sparsebit_next_set(struct sparsebit *sbit, sparsebit_idx_t prev); 4962306a36Sopenharmony_cisparsebit_idx_t sparsebit_next_clear(struct sparsebit *sbit, sparsebit_idx_t prev); 5062306a36Sopenharmony_cisparsebit_idx_t sparsebit_next_set_num(struct sparsebit *sbit, 5162306a36Sopenharmony_ci sparsebit_idx_t start, sparsebit_num_t num); 5262306a36Sopenharmony_cisparsebit_idx_t sparsebit_next_clear_num(struct sparsebit *sbit, 5362306a36Sopenharmony_ci sparsebit_idx_t start, sparsebit_num_t num); 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_civoid sparsebit_set(struct sparsebit *sbitp, sparsebit_idx_t idx); 5662306a36Sopenharmony_civoid sparsebit_set_num(struct sparsebit *sbitp, sparsebit_idx_t start, 5762306a36Sopenharmony_ci sparsebit_num_t num); 5862306a36Sopenharmony_civoid sparsebit_set_all(struct sparsebit *sbitp); 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_civoid sparsebit_clear(struct sparsebit *sbitp, sparsebit_idx_t idx); 6162306a36Sopenharmony_civoid sparsebit_clear_num(struct sparsebit *sbitp, 6262306a36Sopenharmony_ci sparsebit_idx_t start, sparsebit_num_t num); 6362306a36Sopenharmony_civoid sparsebit_clear_all(struct sparsebit *sbitp); 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_civoid sparsebit_dump(FILE *stream, struct sparsebit *sbit, 6662306a36Sopenharmony_ci unsigned int indent); 6762306a36Sopenharmony_civoid sparsebit_validate_internal(struct sparsebit *sbit); 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci#ifdef __cplusplus 7062306a36Sopenharmony_ci} 7162306a36Sopenharmony_ci#endif 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci#endif /* SELFTEST_KVM_SPARSEBIT_H */ 74