Add clang format and used it for bitset (#240)
* Add clang format file .clang-format * Use clang format on bitset --------- Co-authored-by: MeirGavish <meir.gavish@gmail.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
UseTab: Never
|
||||
|
||||
# Allman brace style
|
||||
BreakBeforeBraces: Allman
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
|
||||
# Pointer alignment
|
||||
PointerAlignment: Left
|
||||
|
||||
# Column limit
|
||||
ColumnLimit: 120
|
||||
|
||||
# Case labels
|
||||
IndentCaseLabels: true
|
||||
|
||||
# Include sorting
|
||||
SortIncludes: CaseSensitive
|
||||
IncludeBlocks: Regroup
|
||||
|
||||
ContinuationIndentWidth: 4
|
||||
AlignArrayOfStructures: Left
|
||||
PackConstructorInitializers: Never
|
||||
|
||||
SpaceBeforeParens: Custom
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterFunctionDefinitionName: false
|
||||
|
||||
AlignOperands: AlignAfterOperator
|
||||
BreakBeforeBinaryOperators: None
|
||||
|
||||
IndentPPDirectives: AfterHash
|
||||
AlignConsecutiveMacros: Consecutive
|
||||
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AlignAfterOpenBracket: Align
|
||||
|
||||
ReflowComments: true
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: 1
|
||||
@@ -9,9 +9,19 @@ jobs:
|
||||
name: Run Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install clang-format
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y clang-format
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Clang Format
|
||||
run: clang-format --dry-run -Werror include/bitset.h source/bitset.c
|
||||
# Currently contains only the code that has been formatted to conform
|
||||
# When all existing code conforms, change to this:
|
||||
# run: clang-format --dry-run -Werror include/*.h source/*.c
|
||||
|
||||
- name: Run Tests
|
||||
run: cd tests && ./run_tests.sh
|
||||
|
||||
|
||||
+3
-5
@@ -5,8 +5,8 @@
|
||||
#ifndef BITSET_H
|
||||
#define BITSET_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @def BITSET_BITS_PER_WORD
|
||||
@@ -30,7 +30,7 @@
|
||||
* @def BITSET_MAX_BITS
|
||||
* @brief Maximum number of bits in a bitset
|
||||
*/
|
||||
#define BITSET_MAX_BITS BITSET_BITS_PER_WORD * BITSET_ARRAY_SIZE
|
||||
#define BITSET_MAX_BITS (BITSET_BITS_PER_WORD * BITSET_ARRAY_SIZE)
|
||||
|
||||
/**
|
||||
* @brief A bitset spread across multiple `uint32_t` words
|
||||
@@ -192,13 +192,11 @@ int bitset_itr_next(BitsetItr* itr);
|
||||
*/
|
||||
#define BITSET_DEFINE(name, capacity) \
|
||||
static uint32_t name##_w[BITSET_ARRAY_SIZE] = {0}; \
|
||||
static Bitset name = \
|
||||
{ \
|
||||
static Bitset name = { \
|
||||
.w = name##_w, \
|
||||
.nbits = BITSET_BITS_PER_WORD, \
|
||||
.nwords = BITSET_ARRAY_SIZE, \
|
||||
.cap = capacity, \
|
||||
};
|
||||
|
||||
|
||||
#endif // BITSET_H
|
||||
|
||||
+8
-5
@@ -1,4 +1,5 @@
|
||||
#include "bitset.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
void bitset_set_idx(Bitset* bitset, int idx, bool on)
|
||||
@@ -61,7 +62,8 @@ bool bitset_is_empty(Bitset *bitset)
|
||||
{
|
||||
for (int i = 0; i < bitset->nwords; i++)
|
||||
{
|
||||
if(bitset->w[i]) return false;
|
||||
if (bitset->w[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -98,8 +100,10 @@ int bitset_find_idx_of_nth_set(const Bitset *bitset, int n)
|
||||
if (tracker > n)
|
||||
{
|
||||
// The index is here somewhere
|
||||
int base = prev_tracker - 1; // this one is to count the 1's not the offset, underflow to -1 is good for finding the 0 index
|
||||
int offset = bitset->nbits * i; // this one is for the actual offset we want to map the id to
|
||||
// this one is to count the 1's not the offset, underflow to -1 is good for finding the 0 index
|
||||
int base = prev_tracker - 1;
|
||||
// this one is for the actual offset we want to map the id to
|
||||
int offset = bitset->nbits * i;
|
||||
for (int j = 0; j < bitset->nbits; j++)
|
||||
{
|
||||
if (base == n)
|
||||
@@ -121,8 +125,7 @@ int bitset_find_idx_of_nth_set(const Bitset *bitset, int n)
|
||||
|
||||
BitsetItr bitset_itr_create(const Bitset* bitset)
|
||||
{
|
||||
BitsetItr itr =
|
||||
{
|
||||
BitsetItr itr = {
|
||||
.bitset = bitset,
|
||||
.word = 0,
|
||||
.bit = 0,
|
||||
|
||||
Reference in New Issue
Block a user