Skip to content

Commit

Permalink
👷 (lint): Added a clang format GitHub Action workflow + configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
theobori committed Sep 1, 2024
1 parent d863a4a commit cd4cda7
Show file tree
Hide file tree
Showing 27 changed files with 901 additions and 738 deletions.
246 changes: 246 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveShortCaseStatements:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCaseColons: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Never
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAdjacentStringLiterals: true
BreakAfterAttributes: Leave
BreakAfterJavaFieldAnnotations: false
BreakArrays: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Attach
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
BinaryMinDigits: 0
Decimal: 0
DecimalMinDigits: 0
Hex: 0
HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
KeepEmptyLinesAtEOF: false
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakScopeResolution: 500
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
PPIndentWidth: -1
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveParentheses: Leave
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SkipMacroDefinitionBody: false
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterPlacementOperator: true
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParens: Never
SpacesInParensOptions:
InCStyleCasts: false
InConditionalStatements: false
InEmptyParentheses: false
Other: false
SpacesInSquareBrackets: false
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
VerilogBreakBetweenInstancePorts: true
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE
...

6 changes: 6 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git/*
.github/*
.direnv/*
build/*
result/*
tests/munit/*
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "build"
name: build

on:
pull_request:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: lint

on:
push:
pull_request:

jobs:
lint:
name: Formatting Check
runs-on: ubuntu-latest
strategy:
matrix:
path:
- "src"
- "tests"
steps:
- uses: actions/checkout@v4
- name: Run clang-format style check for C/C++/Protobuf programs.
uses: jidicula/clang-format-action@v4.13.0
with:
clang-format-version: "18"
check-path: ${{ matrix.path }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# C hashmap implementations

[![build](https://github.com/theobori/tinyhash/actions/workflows/build.yml/badge.svg)](https://github.com/theobori/tinyhash/actions/workflows/build.yml)
[![build](https://github.com/theobori/tinyhash/actions/workflows/build.yml/badge.svg)](https://github.com/theobori/tinyhash/actions/workflows/build.yml) [![lint](https://github.com/theobori/tinyhash/actions/workflows/lint.yml/badge.svg)](https://github.com/theobori/tinyhash/actions/workflows/lint.yml)

This is a library containing multiple C implementations of hashmap. The public API is deliberately simple and user-friendly.

Expand Down
27 changes: 11 additions & 16 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
project (tinyhash-lib)
project(tinyhash-lib)

set (TINYHASH_NAME "tinyhash" CACHE INTERNAL "")
set(TINYHASH_NAME "tinyhash" CACHE INTERNAL "")

if (BUILD_STATIC)
set (TINYHASH_LIB_TYPE STATIC)
else ()
set (TINYHASH_LIB_TYPE SHARED)
endif ()
set(TINYHASH_LIB_TYPE STATIC)
else()
set(TINYHASH_LIB_TYPE SHARED)
endif()

add_subdirectory(common)
add_subdirectory(separate_chaining)
add_subdirectory(open_addressing)

set (TINYHASH_SRC
tinyhash.c
)
set(TINYHASH_SRC tinyhash.c)

set (TINYHASH_HEADERS
tinyhash.h
)
set(TINYHASH_HEADERS tinyhash.h)

add_library(
${TINYHASH_NAME} ${TINYHASH_LIB_TYPE}
add_library(${TINYHASH_NAME} ${TINYHASH_LIB_TYPE}
${TINYHASH_SRC}
$<TARGET_OBJECTS:common_objects>
$<TARGET_OBJECTS:separate_chaining_objects>
$<TARGET_OBJECTS:open_addressing_objects>
)

install (TARGETS ${TINYHASH_NAME} DESTINATION lib)
install (FILES ${TINYHASH_HEADERS} DESTINATION include/${TINYHASH_NAME})
install(TARGETS ${TINYHASH_NAME} DESTINATION lib)
install(FILES ${TINYHASH_HEADERS} DESTINATION include/${TINYHASH_NAME})
20 changes: 10 additions & 10 deletions src/common/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
#define TH_HASH_INITIAL_VALUE 2166136261u
#define TH_HASH_MUL_VALUE 16777619

uint32_t th_hash(uint8_t *bytes, size_t size)
{
if (bytes == NULL) return 0;

uint32_t hash = TH_HASH_INITIAL_VALUE;
uint32_t th_hash(uint8_t *bytes, size_t size) {
if (bytes == NULL)
return 0;

for (int i = 0; i < size; i++) {
hash ^= bytes[i];
hash *= TH_HASH_MUL_VALUE;
}
uint32_t hash = TH_HASH_INITIAL_VALUE;

return hash;
for (int i = 0; i < size; i++) {
hash ^= bytes[i];
hash *= TH_HASH_MUL_VALUE;
}

return hash;
}
24 changes: 12 additions & 12 deletions src/common/key.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#include "key.h"

#include <string.h>

#include "key.h"
#include "hash.h"

th_key_t th_key_create(th_any_t data, size_t size)
{
return (th_key_t) {
.hash = th_hash(data, size),
.size = size,
.data = data,
};
th_key_t th_key_create(th_any_t data, size_t size) {
return (th_key_t){
.hash = th_hash(data, size),
.size = size,
.data = data,
};
}

bool th_key_is_equal(th_key_t *first, th_key_t *second)
{
if (first->size != second->size) return false;
bool th_key_is_equal(th_key_t *first, th_key_t *second) {
if (first->size != second->size)
return false;

return memcmp(first->data, second->data, first->size) == 0;
return memcmp(first->data, second->data, first->size) == 0;
}
Loading

0 comments on commit cd4cda7

Please sign in to comment.