Initial commit

This commit is contained in:
2025-11-06 10:36:22 +08:00
commit cac8cf6ad7
20 changed files with 2373 additions and 0 deletions

246
.gitignore vendored Normal file
View File

@@ -0,0 +1,246 @@
### C++ ###
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
### CMake ###
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
### CMake Patch ###
CMakeUserPresets.json
# External projects
*-prefix/
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/
# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml
# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/
# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$
# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml
# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml
### Linux ###
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### MicrosoftOffice ###
*.tmp
# Word temporary
~$*.doc*
# Word Auto Backup File
Backup of *.doc*
# Excel temporary
~$*.xls*
# Excel Backup File
*.xlk
# PowerPoint temporary
~$*.ppt*
# Visio autosave temporary files
*.~vsd*
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide
### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

2
.idea/Experiment.iml generated Normal file
View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

344
.idea/editor.xml generated Normal file
View File

@@ -0,0 +1,344 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BackendCodeEditorSettings">
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CDeclarationWithImplicitIntType/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CommentTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConstevalIfIsAlwaysConstant/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractClassWithoutSpecifier/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractFinalClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractVirtualFunctionCallInCtor/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAccessSpecifierWithNoDeclarations/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAwaiterTypeIsNotClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBooleanIncrementExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatBadCode/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatLegacyCode/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatMixedArgs/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooFewArgs/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooManyArgs/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCVQualifierCanNotBeAppliedToReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassIsIncomplete/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeedsConstructorBecauseOfUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCompileTimeConstantCanBeReplacedWithBooleanConstant/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConceptNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConditionalExpressionCanBeSimplified/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConstParameterInDeclaration/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConstValueFunctionReturnType/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCoroutineCallResolveError/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAArrayIndexOutOfBounds/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantConditions/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantFunctionResult/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantParameter/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFADeletedPointer/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAEndlessLoop/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAInfiniteRecursion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAInvalidatedMemory/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALocalValueEscapesFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALocalValueEscapesScope/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALoopConditionNotUpdated/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAMemoryLeak/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFANotInitializedField/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFANullDereference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFATimeOver/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreachableCode/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreachableFunctionCall/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreadVariable/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnusedValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationHidesLocal/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationHidesUncapturedLocal/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationSpecifierWithoutDeclarators/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorDisambiguatedAsFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorUsedBeforeInitialization/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultCaseNotHandledInSwitchStatement/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultInitializationWithNoUserConstructor/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultIsUsedAsIdentifier/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultedSpecialMemberFunctionIsImplicitlyDeleted/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeletingVoidPointer/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTemplateWithoutTemplateKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTypeWithoutTypenameKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedEntity/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedOverridenMethod/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedRegisterStorageClassSpecifier/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDereferenceOperatorLimitExceeded/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDiscardedPostfixOperatorResult/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenSyntaxError/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenUndocumentedParameter/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenUnresolvedReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEmptyDeclaration/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceCVQualifiersOrder/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceCVQualifiersPlacement/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceDoStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceForStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceFunctionDeclarationStyle/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceIfStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceNestedNamespacesStyle/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceOverridingDestructorStyle/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceOverridingFunctionStyle/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceTypeAliasCodeStyle/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceWhileStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEntityAssignedButNoRead/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEntityUsedOnlyInUnevaluatedContext/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnumeratorNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEqualOperandsInBinaryExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEvaluationFailure/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppExplicitSpecializationInNonNamespaceScope/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppExpressionWithoutSideEffects/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFinalFunctionInFinalClass/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFinalNonOverridingVirtualFunction/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppForLoopCanBeReplacedWithWhile/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppForwardEnumDeclarationWithoutUnderlyingType/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionDoesntReturnValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionIsNotImplemented/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionResultShouldBeUsed/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionalStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHeaderHasBeenAlreadyIncluded/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHiddenFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHidingFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIdenticalOperandsInBinaryExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIfCanBeReplacedByConstexprIf/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppImplicitDefaultConstructorNotAvailable/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompatiblePointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompleteSwitchStatement/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInconsistentNaming/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIntegralToPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInvalidLineContinuation/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppJoinDeclarationAndAssignment/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLambdaCaptureNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMayBeConst/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableWithNonTrivialDtorIsNeverUsed/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLongFloat/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeConst/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeStatic/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberInitializersOrder/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMismatchedClassTags/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingIncludeGuard/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingKeywordThrow/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtAddressOfClassRValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtBindingRValueToLvalueReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtCopyElisionInCopyInitDeclarator/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtDoubleUserConversionInCopyInit/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtNotInitializedStaticConstLocalVar/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtReinterpretCastFromNullptr/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMultiCharacterLiteral/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMultiCharacterWideLiteral/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMustBePublicVirtualToImplementInterface/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMutableSpecifierOnReferenceMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNoDiscardExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNodiscardFunctionWithoutReturnValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExceptionSafeResourceAcquisition/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExplicitConversionOperator/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExplicitConvertingConstructor/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonInlineFunctionDefinitionInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonInlineVariableDefinitionInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNotAllPathsReturnValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppObjectMemberMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppOutParameterMustBeWritten/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterMayBeConst/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterMayBeConstPtrOrRef/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterNamesMismatch/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPassValueParameterByConstReference/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPointerConversionDropsQualifiers/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPointerToIntegralConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPolymorphicClassWithNonVirtualPublicDestructor/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyErroneousEmptyStatements/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyUnintendedObjectSlicing/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrecompiledHeaderIsNotIncluded/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrecompiledHeaderNotFound/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfBadFormat/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfExtraArg/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfMissedArg/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfRiskyFormat/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrivateSpecialMemberFunctionIsNotImplemented/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRangeBasedForIncompatibleReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedefinitionOfDefaultArgumentInOverrideFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantAccessSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBaseClassAccessSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBaseClassInitializer/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBooleanExpressionArgument/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantCastExpression/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantComplexityInComparison/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantConditionalExpression/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantConstSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantControlFlowJump/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantDereferencingAndTakingAddress/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElaboratedTypeSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElseKeyword/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElseKeywordInsideCompoundStatement/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantEmptyDeclaration/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantEmptyStatement/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantExportKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantFwdClassOrEnumSpecifier/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantInlineSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantLambdaParameterList/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantMemberInitializer/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantNamespaceDefinition/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantParentheses/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantQualifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantQualifierADL/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantStaticSpecifierOnMemberAllocationFunction/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantStaticSpecifierOnThreadLocalLocalVariable/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTemplateArguments/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTemplateKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTypenameKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantVoidArgumentList/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantZeroInitializerInAggregateInitialization/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReinterpretCastFromVoidPtr/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRemoveRedundantBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReplaceMemsetWithZeroInitialization/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReplaceTieWithStructuredBinding/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReturnNoValueInNonVoidFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSmartPointerVsMakeFunction/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSomeObjectMembersMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSpecialFunctionWithoutNoexceptSpecification/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticAssertFailure/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticDataMemberInUnnamedStruct/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticSpecifierOnAnonymousNamespaceMember/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStringLiteralToCharPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateArgumentsCanBeDeduced/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterShadowing/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppThrowExpressionCanBeReplacedWithRethrow/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTooWideScope/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTooWideScopeInitStatement/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTypeAliasNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUninitializedDependentBaseClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUninitializedNonStaticDataMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnionMemberOfReferenceType/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaEndRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnamedNamespaceInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnsignedZeroComparison/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnusedIncludeDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAlgorithmWithCount/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAssociativeContains/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAuto/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAutoForNumeric/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseElementsView/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseEraseAlgorithm/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseFamiliarTemplateSyntaxForGenericLambdas/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseRangeAlgorithm/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseStdSize/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseStructuredBinding/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseTypeTraitAlias/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUserDefinedLiteralSuffixDoesNotStartWithUnderscore/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUsingResultOfAssignmentAsCondition/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVariableCanBeMadeConstexpr/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVirtualFunctionCallInsideCtor/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVirtualFunctionInFinalClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVolatileParameterInDeclaration/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWarningDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWrongIncludesOrder/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWrongSlashesInIncludeDirective/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppZeroConstantCanBeReplacedWithNullptr/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppZeroValuedExpressionUsedAsNullPointer/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IdentifierTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IfStdIsConstantEvaluatedCanBeReplaced/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StdIsConstantEvaluatedWillAlwaysEvaluateToConstant/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_ARGUMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_BINARY_EXPRESSIONS_CHAIN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXPRESSION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_FOR_STMT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_PARAMETER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_ARGUMENT/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_PARAMETER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_TERNARY/@EntryValue" value="ALIGN_ALL" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_CLASS_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_DECLARATIONS/@EntryValue" value="0" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DECLARATION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BREAK_TEMPLATE_DECLARATION/@EntryValue" value="LINE_BREAK" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/FREE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_ACCESS_SPECIFIERS_FROM_CLASS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_COMMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_STYLE/@EntryValue" value="Space" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INITIALIZER_BRACES/@EntryValue" value="END_OF_LINE_NO_SPACE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_EQ/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_CODE/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COLON_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/MEMBER_INITIALIZER_LIST_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue" value="All" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_CATCH_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_ELSE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_NAMESPACE_DEFINITIONS_ON_SAME_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_WHILE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_BLOCK_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_SEMICOLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_METHOD/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_NESTED_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_METHOD/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_UNARY_OPERATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_COLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_SEMICOLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_METHOD/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_METHOD/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BETWEEN_CLOSING_ANGLE_BRACKETS_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_ARRAY_ACCESS_BRACKETS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_DECLARATION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_BLOCKS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_METHOD_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_ARGUMENTS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_TERNARY_OPSIGNS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_PARAMETERS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
</component>
</project>

7
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Experiment.iml" filepath="$PROJECT_DIR$/.idea/Experiment.iml" />
</modules>
</component>
</project>

4
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings" defaultProject="true" />
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

12
CMakeLists.txt Normal file
View File

@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 4.0)
project(Experiment)
set(CMAKE_CXX_STANDARD 20)
add_executable(CPUScheduler CPUScheduler.cpp)
add_executable(ProcessSync ProcessSync.cpp)
add_executable(DeadlockAvoid DeadlockAvoid.cpp)
add_executable(MemoryManager MemoryManager.cpp)

435
CPUScheduler.cpp Normal file
View File

@@ -0,0 +1,435 @@
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
// 进程结构体
struct Process {
int pid; // 进程ID
int arrivalTime; // 到达时间
int burstTime; // 服务时间
int priority; // 优先级(数值越小优先级越高)
int remainingTime; // 剩余时间
int finishTime; // 完成时间
int turnaroundTime; // 周转时间
int waitingTime; // 等待时间
double responseRatio; // 响应比(用于HRRN)
Process(int p, int a, int b, int pr = 0) {
pid = p;
arrivalTime = a;
burstTime = b;
priority = pr;
remainingTime = b;
finishTime = 0;
turnaroundTime = 0;
waitingTime = 0;
responseRatio = 0.0;
}
};
class CPUScheduler {
private:
vector<Process> processes;
vector<Process> originalProcesses;
public:
// 添加进程
void addProcess(int pid, int arrivalTime, int burstTime, int priority = 0) {
processes.push_back(Process(pid, arrivalTime, burstTime, priority));
originalProcesses.push_back(Process(pid, arrivalTime, burstTime, priority));
}
// 重置进程状态
void resetProcesses() {
processes = originalProcesses;
for (auto& p : processes) {
p.remainingTime = p.burstTime;
p.finishTime = 0;
p.turnaroundTime = 0;
p.waitingTime = 0;
p.responseRatio = 0.0;
}
}
// 先来先服务(FCFS)算法
void FCFS() {
cout << "\n========== 先来先服务(FCFS)调度算法 ==========\n";
resetProcesses();
// 按到达时间排序
sort(processes.begin(), processes.end(),
[](const Process& a, const Process& b) {
return a.arrivalTime < b.arrivalTime;
});
int currentTime = 0;
cout << "执行顺序: ";
for (auto& p : processes) {
// 如果当前时间小于进程到达时间CPU空闲
if (currentTime < p.arrivalTime) {
currentTime = p.arrivalTime;
}
cout << "P" << p.pid << " ";
currentTime += p.burstTime;
p.finishTime = currentTime;
p.turnaroundTime = p.finishTime - p.arrivalTime;
p.waitingTime = p.turnaroundTime - p.burstTime;
}
cout << "\n";
printResults();
}
// 最短作业优先(SJF)算法
void SJF() {
cout << "\n========== 最短作业优先(SJF)调度算法 ==========\n";
resetProcesses();
vector<Process> readyQueue;
vector<Process> completed;
int currentTime = 0;
cout << "执行顺序: ";
while (completed.size() < processes.size()) {
// 将已到达的进程加入就绪队列
for (auto& p : processes) {
if (p.arrivalTime <= currentTime && p.finishTime == 0) {
bool inQueue = false;
for (const auto& q : readyQueue) {
if (q.pid == p.pid) {
inQueue = true;
break;
}
}
if (!inQueue) {
readyQueue.push_back(p);
}
}
}
if (!readyQueue.empty()) {
// 选择服务时间最短的进程
auto shortestJob = min_element(readyQueue.begin(), readyQueue.end(),
[](const Process& a, const Process& b) {
return a.burstTime < b.burstTime;
});
cout << "P" << shortestJob->pid << " ";
currentTime += shortestJob->burstTime;
// 更新原进程信息
for (auto& p : processes) {
if (p.pid == shortestJob->pid) {
p.finishTime = currentTime;
p.turnaroundTime = p.finishTime - p.arrivalTime;
p.waitingTime = p.turnaroundTime - p.burstTime;
completed.push_back(p);
break;
}
}
// 从就绪队列中移除已完成的进程
readyQueue.erase(shortestJob);
} else {
currentTime++;
}
}
cout << "\n";
printResults();
}
// 最短剩余时间优先(SRTF)算法
void SRTF() {
cout << "\n========== 最短剩余时间优先(SRTF)调度算法 ==========\n";
resetProcesses();
int currentTime = 0;
int completed = 0;
vector<int> executionOrder;
while (completed < processes.size()) {
int shortestIdx = -1;
int shortestTime = INT_MAX;
// 找到当前时间已到达且剩余时间最短的进程
for (int i = 0; i < processes.size(); i++) {
if (processes[i].arrivalTime <= currentTime &&
processes[i].remainingTime > 0 &&
processes[i].remainingTime < shortestTime) {
shortestTime = processes[i].remainingTime;
shortestIdx = i;
}
}
if (shortestIdx == -1) {
currentTime++;
continue;
}
// 执行选中的进程1个时间单位
executionOrder.push_back(processes[shortestIdx].pid);
processes[shortestIdx].remainingTime--;
currentTime++;
// 如果进程完成
if (processes[shortestIdx].remainingTime == 0) {
processes[shortestIdx].finishTime = currentTime;
processes[shortestIdx].turnaroundTime =
processes[shortestIdx].finishTime - processes[shortestIdx].arrivalTime;
processes[shortestIdx].waitingTime =
processes[shortestIdx].turnaroundTime - processes[shortestIdx].burstTime;
completed++;
}
}
// 输出执行顺序(去重连续相同的进程)
cout << "执行顺序: ";
if (!executionOrder.empty()) {
cout << "P" << executionOrder[0];
for (int i = 1; i < executionOrder.size(); i++) {
if (executionOrder[i] != executionOrder[i-1]) {
cout << " P" << executionOrder[i];
}
}
}
cout << "\n";
printResults();
}
// 最高响应比优先(HRRN)算法
void HRRN() {
cout << "\n========== 最高响应比优先(HRRN)调度算法 ==========\n";
resetProcesses();
vector<Process> completed;
int currentTime = 0;
cout << "执行顺序: ";
while (completed.size() < processes.size()) {
vector<int> readyQueue;
// 找到所有已到达且未完成的进程
for (int i = 0; i < processes.size(); i++) {
if (processes[i].arrivalTime <= currentTime && processes[i].finishTime == 0) {
readyQueue.push_back(i);
}
}
if (!readyQueue.empty()) {
// 计算响应比并选择最高的
int selectedIdx = -1;
double highestRatio = 0.0;
for (int idx : readyQueue) {
int waitTime = currentTime - processes[idx].arrivalTime;
processes[idx].responseRatio =
(double)(waitTime + processes[idx].burstTime) / processes[idx].burstTime;
if (processes[idx].responseRatio > highestRatio) {
highestRatio = processes[idx].responseRatio;
selectedIdx = idx;
}
}
cout << "P" << processes[selectedIdx].pid << " ";
currentTime += processes[selectedIdx].burstTime;
processes[selectedIdx].finishTime = currentTime;
processes[selectedIdx].turnaroundTime =
processes[selectedIdx].finishTime - processes[selectedIdx].arrivalTime;
processes[selectedIdx].waitingTime =
processes[selectedIdx].turnaroundTime - processes[selectedIdx].burstTime;
completed.push_back(processes[selectedIdx]);
} else {
currentTime++;
}
}
cout << "\n";
printResults();
}
// 时间片轮转(RR)算法
void RR(int timeQuantum = 2) {
cout << "\n========== 时间片轮转(RR)调度算法 (时间片=" << timeQuantum << ") ==========\n";
resetProcesses();
queue<int> readyQueue;
vector<bool> inQueue(processes.size(), false);
int currentTime = 0;
int completed = 0;
cout << "执行顺序: ";
// 将时间0到达的进程加入队列
for (int i = 0; i < processes.size(); i++) {
if (processes[i].arrivalTime <= currentTime) {
readyQueue.push(i);
inQueue[i] = true;
}
}
while (completed < processes.size()) {
if (readyQueue.empty()) {
currentTime++;
// 检查是否有新进程到达
for (int i = 0; i < processes.size(); i++) {
if (processes[i].arrivalTime <= currentTime &&
!inQueue[i] && processes[i].remainingTime > 0) {
readyQueue.push(i);
inQueue[i] = true;
}
}
continue;
}
int currentProcess = readyQueue.front();
readyQueue.pop();
inQueue[currentProcess] = false;
cout << "P" << processes[currentProcess].pid << " ";
// 执行时间片或直到进程完成
int executeTime = min(timeQuantum, processes[currentProcess].remainingTime);
currentTime += executeTime;
processes[currentProcess].remainingTime -= executeTime;
// 将在执行期间到达的进程加入队列
for (int i = 0; i < processes.size(); i++) {
if (processes[i].arrivalTime <= currentTime &&
!inQueue[i] && processes[i].remainingTime > 0 && i != currentProcess) {
readyQueue.push(i);
inQueue[i] = true;
}
}
// 如果当前进程还未完成,重新加入队列
if (processes[currentProcess].remainingTime > 0) {
readyQueue.push(currentProcess);
inQueue[currentProcess] = true;
} else {
// 进程完成
processes[currentProcess].finishTime = currentTime;
processes[currentProcess].turnaroundTime =
processes[currentProcess].finishTime - processes[currentProcess].arrivalTime;
processes[currentProcess].waitingTime =
processes[currentProcess].turnaroundTime - processes[currentProcess].burstTime;
completed++;
}
}
cout << "\n";
printResults();
}
// 优先级调度算法(非抢占)
void PriorityScheduling() {
cout << "\n========== 优先级调度算法(非抢占) ==========\n";
resetProcesses();
vector<Process> completed;
int currentTime = 0;
cout << "执行顺序: ";
while (completed.size() < processes.size()) {
vector<int> readyQueue;
// 找到所有已到达且未完成的进程
for (int i = 0; i < processes.size(); i++) {
if (processes[i].arrivalTime <= currentTime && processes[i].finishTime == 0) {
readyQueue.push_back(i);
}
}
if (!readyQueue.empty()) {
// 选择优先级最高的进程(数值最小)
int selectedIdx = readyQueue[0];
for (int idx : readyQueue) {
if (processes[idx].priority < processes[selectedIdx].priority) {
selectedIdx = idx;
}
}
cout << "P" << processes[selectedIdx].pid << " ";
currentTime += processes[selectedIdx].burstTime;
processes[selectedIdx].finishTime = currentTime;
processes[selectedIdx].turnaroundTime =
processes[selectedIdx].finishTime - processes[selectedIdx].arrivalTime;
processes[selectedIdx].waitingTime =
processes[selectedIdx].turnaroundTime - processes[selectedIdx].burstTime;
completed.push_back(processes[selectedIdx]);
} else {
currentTime++;
}
}
cout << "\n";
printResults();
}
// 打印结果
void printResults() {
cout << "\n进程调度结果:\n";
cout << "进程ID\t到达时间\t服务时间\t完成时间\t周转时间\t等待时间\n";
cout << "--------------------------------------------------------------\n";
double totalTurnaround = 0, totalWaiting = 0;
for (const auto& p : processes) {
cout << "P" << p.pid << "\t" << p.arrivalTime << "\t\t"
<< p.burstTime << "\t\t" << p.finishTime << "\t\t"
<< p.turnaroundTime << "\t\t" << p.waitingTime << "\n";
totalTurnaround += p.turnaroundTime;
totalWaiting += p.waitingTime;
}
cout << "--------------------------------------------------------------\n";
cout << fixed << setprecision(2);
cout << "平均周转时间: " << totalTurnaround / processes.size() << "\n";
cout << "平均等待时间: " << totalWaiting / processes.size() << "\n";
}
// 显示所有进程信息
void displayProcesses() {
cout << "\n当前进程信息:\n";
cout << "进程ID\t到达时间\t服务时间\t优先级\n";
cout << "----------------------------------------\n";
for (const auto& p : originalProcesses) {
cout << "P" << p.pid << "\t" << p.arrivalTime << "\t\t"
<< p.burstTime << "\t\t" << p.priority << "\n";
}
}
};
int main() {
CPUScheduler scheduler;
cout << "处理机调度算法实验\n";
cout << "==================\n";
// 示例进程数据
cout << "使用示例进程数据进行测试:\n";
scheduler.addProcess(1, 0, 8, 3); // 进程P1: 到达时间0, 服务时间8, 优先级3
scheduler.addProcess(2, 1, 4, 1); // 进程P2: 到达时间1, 服务时间4, 优先级1
scheduler.addProcess(3, 2, 2, 4); // 进程P3: 到达时间2, 服务时间2, 优先级4
scheduler.addProcess(4, 3, 1, 2); // 进程P4: 到达时间3, 服务时间1, 优先级2
scheduler.addProcess(5, 4, 3, 5); // 进程P5: 到达时间4, 服务时间3, 优先级5
scheduler.displayProcesses();
// 执行各种调度算法
scheduler.FCFS();
scheduler.SJF();
scheduler.SRTF();
scheduler.HRRN();
scheduler.RR(2);
scheduler.PriorityScheduling();
return 0;
}

507
DeadlockAvoid.cpp Normal file
View File

@@ -0,0 +1,507 @@
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
class BankersAlgorithm {
private:
int n; // 进程数量
int m; // 资源类型数量
vector<vector<int>> allocation; // 分配矩阵
vector<vector<int>> max; // 最大需求矩阵
vector<vector<int>> need; // 需求矩阵
vector<int> available; // 可用资源向量
public:
// 构造函数,初始化银行家算法
BankersAlgorithm(int processes, int resources) {
n = processes;
m = resources;
allocation.resize(n, vector<int>(m, 0));
max.resize(n, vector<int>(m, 0));
need.resize(n, vector<int>(m, 0));
available.resize(m, 0);
}
// 加载测试数据集1安全状态测试
void loadTestData1() {
cout << "加载测试数据集1安全状态测试5进程3资源" << endl;
n = 5; m = 3;
// 重新调整矩阵大小
allocation.resize(n, vector<int>(m));
max.resize(n, vector<int>(m));
need.resize(n, vector<int>(m));
available.resize(m);
// 可用资源向量
available = {3, 3, 2};
// 分配矩阵
allocation = {
{0, 1, 0},
{2, 0, 0},
{3, 0, 2},
{2, 1, 1},
{0, 0, 2}
};
// 最大需求矩阵
max = {
{7, 5, 3},
{3, 2, 2},
{9, 0, 2},
{2, 2, 2},
{4, 3, 3}
};
calculateNeedMatrix();
cout << "测试数据集1加载完成预期系统安全安全序列如P1->P3->P4->P2->P0" << endl;
}
// 加载测试数据集2不安全状态测试
void loadTestData2() {
cout << "加载测试数据集2不安全状态测试3进程3资源" << endl;
n = 3; m = 3;
// 重新调整矩阵大小
allocation.resize(n, vector<int>(m));
max.resize(n, vector<int>(m));
need.resize(n, vector<int>(m));
available.resize(m);
// 可用资源向量
available = {1, 0, 0};
// 分配矩阵
allocation = {
{1, 2, 0},
{2, 0, 1},
{0, 1, 2}
};
// 最大需求矩阵
max = {
{3, 3, 2},
{4, 2, 2},
{3, 3, 3}
};
calculateNeedMatrix();
cout << "测试数据集2加载完成预期系统不安全" << endl;
}
// 加载测试数据集3边界情况测试
void loadTestData3() {
cout << "加载测试数据集3边界情况测试2进程2资源" << endl;
n = 2; m = 2;
// 重新调整矩阵大小
allocation.resize(n, vector<int>(m));
max.resize(n, vector<int>(m));
need.resize(n, vector<int>(m));
available.resize(m);
// 可用资源向量
available = {2, 2};
// 分配矩阵
allocation = {
{1, 0},
{0, 1}
};
// 最大需求矩阵
max = {
{3, 2},
{2, 3}
};
calculateNeedMatrix();
cout << "测试数据集3加载完成预期系统安全安全序列如P0->P1或P1->P0" << endl;
}
// 输入系统状态信息
void inputSystemState() {
cout << "请输入可用资源向量Available" << m << "个资源类型):";
for (int i = 0; i < m; i++) {
cin >> available[i];
}
cout << "请输入分配矩阵Allocation" << endl;
for (int i = 0; i < n; i++) {
cout << "进程P" << i << "";
for (int j = 0; j < m; j++) {
cin >> allocation[i][j];
}
}
cout << "请输入最大需求矩阵Max" << endl;
for (int i = 0; i < n; i++) {
cout << "进程P" << i << "";
for (int j = 0; j < m; j++) {
cin >> max[i][j];
}
}
// 计算需求矩阵Need = Max - Allocation
calculateNeedMatrix();
}
// 计算需求矩阵
void calculateNeedMatrix() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
need[i][j] = max[i][j] - allocation[i][j];
}
}
}
// 显示当前系统状态
void displaySystemState() {
cout << "\n=== 当前系统状态 ===" << endl;
// 显示可用资源
cout << "可用资源Available";
for (int i = 0; i < m; i++) {
cout << setw(4) << available[i];
}
cout << endl;
// 显示各矩阵
cout << "\n进程\t分配矩阵Allocation\t最大需求矩阵Max\t\t需求矩阵Need" << endl;
for (int i = 0; i < n; i++) {
cout << "P" << i << "\t";
// 分配矩阵
for (int j = 0; j < m; j++) {
cout << setw(3) << allocation[i][j];
}
cout << "\t\t";
// 最大需求矩阵
for (int j = 0; j < m; j++) {
cout << setw(3) << max[i][j];
}
cout << "\t\t";
// 需求矩阵
for (int j = 0; j < m; j++) {
cout << setw(3) << need[i][j];
}
cout << endl;
}
}
// 安全性检查,返回是否安全及安全序列
bool safetyCheck(vector<int>& safeSequence) {
vector<int> work = available; // 工作向量初始值为Available
vector<bool> finish(n, false); // 完成标记数组
safeSequence.clear();
cout << "\n=== 安全性检查过程 ===" << endl;
cout << "初始工作向量Work";
for (int i = 0; i < m; i++) {
cout << setw(4) << work[i];
}
cout << endl;
int count = 0; // 已完成的进程数量
// 循环查找可以完成的进程
while (count < n) {
bool found = false;
for (int i = 0; i < n; i++) {
// 如果进程i未完成且Need[i] <= Work
if (!finish[i]) {
bool canFinish = true;
for (int j = 0; j < m; j++) {
if (need[i][j] > work[j]) {
canFinish = false;
break;
}
}
if (canFinish) {
// 进程i可以完成
cout << "进程P" << i << "可以完成,需求:";
for (int j = 0; j < m; j++) {
cout << setw(3) << need[i][j];
}
cout << " <= 工作向量:";
for (int j = 0; j < m; j++) {
cout << setw(3) << work[j];
}
cout << endl;
// 更新工作向量Work = Work + Allocation[i]
for (int j = 0; j < m; j++) {
work[j] += allocation[i][j];
}
finish[i] = true;
safeSequence.push_back(i);
count++;
found = true;
cout << "完成后工作向量:";
for (int j = 0; j < m; j++) {
cout << setw(4) << work[j];
}
cout << endl << endl;
break;
}
}
}
// 如果没有找到可以完成的进程,系统不安全
if (!found) {
cout << "无法找到可完成的进程,系统处于不安全状态!" << endl;
return false;
}
}
return true;
}
// 资源请求处理
bool requestResources(int processId, vector<int>& request) {
cout << "\n=== 处理进程P" << processId << "的资源请求 ===" << endl;
cout << "请求向量Request";
for (int i = 0; i < m; i++) {
cout << setw(4) << request[i];
}
cout << endl;
// 步骤1检查Request <= Need
cout << "检查Request <= Need";
for (int i = 0; i < m; i++) {
if (request[i] > need[processId][i]) {
cout << "失败!请求超过需求量" << endl;
return false;
}
}
cout << "通过" << endl;
// 步骤2检查Request <= Available
cout << "检查Request <= Available";
for (int i = 0; i < m; i++) {
if (request[i] > available[i]) {
cout << "失败!请求超过可用资源" << endl;
return false;
}
}
cout << "通过" << endl;
// 步骤3试探性分配
cout << "进行试探性分配..." << endl;
// 保存原始状态
vector<int> originalAvailable = available;
vector<vector<int>> originalAllocation = allocation;
vector<vector<int>> originalNeed = need;
// 修改系统状态
for (int i = 0; i < m; i++) {
available[i] -= request[i];
allocation[processId][i] += request[i];
need[processId][i] -= request[i];
}
cout << "试探性分配后的状态:" << endl;
displaySystemState();
// 步骤4执行安全性检查
vector<int> safeSequence;
bool isSafe = safetyCheck(safeSequence);
if (isSafe) {
cout << "系统处于安全状态!" << endl;
cout << "安全序列:";
for (int i = 0; i < safeSequence.size(); i++) {
cout << "P" << safeSequence[i];
if (i < safeSequence.size() - 1) cout << " -> ";
}
cout << endl;
cout << "资源分配成功!" << endl;
return true;
} else {
// 恢复原始状态
available = originalAvailable;
allocation = originalAllocation;
need = originalNeed;
cout << "分配后系统不安全,拒绝分配,恢复原状态" << endl;
return false;
}
}
// 显示数据选择菜单
void showDataMenu() {
cout << "\n=== 选择测试数据或手动输入 ===" << endl;
cout << "1. 使用测试数据集15进程3资源安全状态" << endl;
cout << "2. 使用测试数据集23进程3资源不安全状态" << endl;
cout << "3. 使用测试数据集32进程2资源边界测试" << endl;
cout << "4. 手动输入系统参数和数据" << endl;
cout << "请选择:";
}
// 显示菜单
void showMenu() {
cout << "\n=== 银行家算法菜单 ===" << endl;
cout << "1. 显示当前系统状态" << endl;
cout << "2. 安全性检查" << endl;
cout << "3. 资源请求处理" << endl;
cout << "4. 重新选择/输入系统数据" << endl;
cout << "5. 测试推荐资源请求" << endl;
cout << "0. 退出程序" << endl;
cout << "请选择操作:";
}
// 提供推荐的测试请求
void showRecommendedRequests() {
cout << "\n=== 推荐的测试请求 ===" << endl;
if (n == 5 && m == 3) {
// 测试数据集1的推荐请求
cout << "当前是测试数据集1推荐测试请求" << endl;
cout << "1. P1请求(1,0,2) - 预期:被拒绝(超过可用资源)" << endl;
cout << "2. P4请求(3,3,0) - 预期:被拒绝(超过可用资源)" << endl;
cout << "3. P1请求(0,2,0) - 预期:可能被接受" << endl;
cout << "4. P3请求(0,1,1) - 预期:应该被接受" << endl;
} else if (n == 3 && m == 3) {
// 测试数据集2的推荐请求
cout << "当前是测试数据集2推荐测试请求" << endl;
cout << "1. 任何进程的任何合理请求都会被拒绝,因为系统已经不安全" << endl;
cout << "2. P0请求(1,0,0) - 预期:被拒绝" << endl;
cout << "3. P1请求(0,1,0) - 预期:被拒绝" << endl;
} else if (n == 2 && m == 2) {
// 测试数据集3的推荐请求
cout << "当前是测试数据集3推荐测试请求" << endl;
cout << "1. P0请求(2,2) - 预期:应该被接受" << endl;
cout << "2. P1请求(2,2) - 预期:应该被接受" << endl;
cout << "3. P0请求(1,1) - 预期:应该被接受" << endl;
} else {
cout << "当前是自定义数据,请根据需求矩阵和可用资源设计测试请求。" << endl;
}
}
// 数据选择和初始化
void initializeData() {
int choice;
showDataMenu();
cin >> choice;
switch (choice) {
case 1:
loadTestData1();
break;
case 2:
loadTestData2();
break;
case 3:
loadTestData3();
break;
case 4:
cout << "请输入进程数量:";
cin >> n;
cout << "请输入资源类型数量:";
cin >> m;
// 重新调整矩阵大小
allocation.resize(n, vector<int>(m, 0));
max.resize(n, vector<int>(m, 0));
need.resize(n, vector<int>(m, 0));
available.resize(m, 0);
inputSystemState();
break;
default:
cout << "无效选择使用测试数据集1" << endl;
loadTestData1();
break;
}
}
// 运行银行家算法主程序
void run() {
cout << "=== 银行家算法死锁避免实验 ===" << endl;
// 数据选择和初始化
initializeData();
// 显示初始状态
displaySystemState();
int choice;
do {
showMenu();
cin >> choice;
switch (choice) {
case 1: {
displaySystemState();
break;
}
case 2: {
vector<int> safeSequence;
bool isSafe = safetyCheck(safeSequence);
if (isSafe) {
cout << "系统处于安全状态!" << endl;
cout << "安全序列:";
for (int i = 0; i < safeSequence.size(); i++) {
cout << "P" << safeSequence[i];
if (i < safeSequence.size() - 1) cout << " -> ";
}
cout << endl;
} else {
cout << "系统处于不安全状态!" << endl;
}
break;
}
case 3: {
int processId;
cout << "请输入请求资源的进程ID0-" << n-1 << "";
cin >> processId;
if (processId < 0 || processId >= n) {
cout << "无效的进程ID" << endl;
break;
}
vector<int> request(m);
cout << "请输入请求的资源向量(" << m << "个值):";
for (int i = 0; i < m; i++) {
cin >> request[i];
}
requestResources(processId, request);
break;
}
case 4: {
initializeData();
displaySystemState();
break;
}
case 5: {
showRecommendedRequests();
break;
}
case 0: {
cout << "感谢使用银行家算法程序!" << endl;
break;
}
default: {
cout << "无效选择,请重新输入!" << endl;
break;
}
}
} while (choice != 0);
}
};
int main() {
// 创建银行家算法实例并运行
BankersAlgorithm banker(0, 0);
banker.run();
return 0;
}

285
MemoryManager.cpp Normal file
View File

@@ -0,0 +1,285 @@
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;
// 分区结构体
struct Partition {
int start; // 起始地址
int size; // 分区大小
bool allocated; // 是否已分配
string process; // 进程名称(已分配分区使用)
Partition(int s, int sz, bool alloc = false, string proc = "")
: start(s), size(sz), allocated(alloc), process(proc) {}
};
class MemoryManager {
private:
vector<Partition> partitions; // 分区列表
int totalMemory; // 总内存大小
int nextFitIndex; // 下次适应算法的起始位置
public:
// 构造函数,初始化内存管理器
MemoryManager(int total) : totalMemory(total), nextFitIndex(0) {
// 初始化时整个内存为一个空闲分区
partitions.push_back(Partition(0, total, false));
}
// 首次适应算法分配内存
bool firstFit(string processName, int size) {
cout << "使用首次适应算法为进程 " << processName << " 分配 " << size << " 单位内存" << endl;
for (int i = 0; i < partitions.size(); i++) {
// 找到第一个足够大的空闲分区
if (!partitions[i].allocated && partitions[i].size >= size) {
return allocatePartition(i, processName, size);
}
}
cout << "分配失败:没有足够的连续空闲空间" << endl;
return false;
}
// 下次适应算法分配内存
bool nextFit(string processName, int size) {
cout << "使用下次适应算法为进程 " << processName << " 分配 " << size << " 单位内存" << endl;
int startIndex = nextFitIndex;
int i = startIndex;
// 从上次分配位置开始查找
do {
if (!partitions[i].allocated && partitions[i].size >= size) {
nextFitIndex = i; // 更新下次查找的起始位置
return allocatePartition(i, processName, size);
}
i = (i + 1) % partitions.size(); // 循环查找
} while (i != startIndex);
cout << "分配失败:没有足够的连续空闲空间" << endl;
return false;
}
// 最佳适应算法分配内存
bool bestFit(string processName, int size) {
cout << "使用最佳适应算法为进程 " << processName << " 分配 " << size << " 单位内存" << endl;
int bestIndex = -1;
int minWaste = INT_MAX;
// 查找最合适的分区(剩余空间最小)
for (int i = 0; i < partitions.size(); i++) {
if (!partitions[i].allocated && partitions[i].size >= size) {
int waste = partitions[i].size - size;
if (waste < minWaste) {
minWaste = waste;
bestIndex = i;
}
}
}
if (bestIndex != -1) {
return allocatePartition(bestIndex, processName, size);
}
cout << "分配失败:没有足够的连续空闲空间" << endl;
return false;
}
// 释放指定进程的内存
bool deallocate(string processName) {
cout << "释放进程 " << processName << " 的内存" << endl;
bool found = false;
for (int i = 0; i < partitions.size(); i++) {
if (partitions[i].allocated && partitions[i].process == processName) {
partitions[i].allocated = false;
partitions[i].process = "";
found = true;
cout << "成功释放进程 " << processName << " 占用的内存" << endl;
}
}
if (found) {
mergePartitions(); // 合并相邻的空闲分区
return true;
}
cout << "释放失败:未找到进程 " << processName << endl;
return false;
}
// 显示当前内存分配状态
void displayMemoryStatus() {
cout << "\n===== 当前内存分配状态 =====" << endl;
cout << "起始地址\t大小\t状态\t\t进程名" << endl;
cout << "----------------------------------------" << endl;
for (const auto& partition : partitions) {
cout << partition.start << "\t\t" << partition.size << "\t";
if (partition.allocated) {
cout << "已分配\t\t" << partition.process;
} else {
cout << "空闲\t\t---";
}
cout << endl;
}
// 统计内存使用情况
int usedMemory = 0;
int freeMemory = 0;
for (const auto& partition : partitions) {
if (partition.allocated) {
usedMemory += partition.size;
} else {
freeMemory += partition.size;
}
}
cout << "----------------------------------------" << endl;
cout << "总内存: " << totalMemory << " 单位" << endl;
cout << "已用内存: " << usedMemory << " 单位" << endl;
cout << "空闲内存: " << freeMemory << " 单位" << endl;
cout << "内存利用率: " << fixed << setprecision(2)
<< (double)usedMemory / totalMemory * 100 << "%" << endl;
cout << "===========================\n" << endl;
}
private:
// 在指定位置分配分区
bool allocatePartition(int index, string processName, int size) {
Partition& partition = partitions[index];
if (partition.size == size) {
// 分区大小正好匹配,直接分配
partition.allocated = true;
partition.process = processName;
} else {
// 分区大小大于所需大小,需要分割
int remainingSize = partition.size - size;
// 修改当前分区为已分配
partition.size = size;
partition.allocated = true;
partition.process = processName;
// 在当前分区后插入剩余的空闲分区
partitions.insert(partitions.begin() + index + 1,
Partition(partition.start + size, remainingSize, false));
}
cout << "分配成功:为进程 " << processName << " 分配了 " << size << " 单位内存" << endl;
return true;
}
// 合并相邻的空闲分区
void mergePartitions() {
// 按起始地址排序
sort(partitions.begin(), partitions.end(),
[](const Partition& a, const Partition& b) {
return a.start < b.start;
});
// 合并相邻的空闲分区
for (int i = 0; i < partitions.size() - 1; ) {
if (!partitions[i].allocated && !partitions[i + 1].allocated &&
partitions[i].start + partitions[i].size == partitions[i + 1].start) {
// 合并两个相邻的空闲分区
partitions[i].size += partitions[i + 1].size;
partitions.erase(partitions.begin() + i + 1);
// 重置下次适应算法的索引
if (nextFitIndex > i) {
nextFitIndex--;
}
} else {
i++;
}
}
}
};
// 显示菜单
void displayMenu() {
cout << "\n===== 可变分区内存管理系统 =====" << endl;
cout << "1. 首次适应算法分配内存" << endl;
cout << "2. 下次适应算法分配内存" << endl;
cout << "3. 最佳适应算法分配内存" << endl;
cout << "4. 释放内存" << endl;
cout << "5. 显示内存状态" << endl;
cout << "6. 退出系统" << endl;
cout << "===============================" << endl;
cout << "请选择操作: ";
}
int main() {
cout << "欢迎使用可变分区内存管理系统!" << endl;
cout << "请输入总内存大小: ";
int totalMemory;
cin >> totalMemory;
MemoryManager memManager(totalMemory);
int choice;
string processName;
int size;
while (true) {
displayMenu();
cin >> choice;
switch (choice) {
case 1: // 首次适应算法
cout << "请输入进程名: ";
cin >> processName;
cout << "请输入需要分配的内存大小: ";
cin >> size;
memManager.firstFit(processName, size);
break;
case 2: // 下次适应算法
cout << "请输入进程名: ";
cin >> processName;
cout << "请输入需要分配的内存大小: ";
cin >> size;
memManager.nextFit(processName, size);
break;
case 3: // 最佳适应算法
cout << "请输入进程名: ";
cin >> processName;
cout << "请输入需要分配的内存大小: ";
cin >> size;
memManager.bestFit(processName, size);
break;
case 4: // 释放内存
cout << "请输入要释放的进程名: ";
cin >> processName;
memManager.deallocate(processName);
break;
case 5: // 显示内存状态
memManager.displayMemoryStatus();
break;
case 6: // 退出系统
cout << "感谢使用可变分区内存管理系统,再见!" << endl;
return 0;
default:
cout << "无效选择,请重新输入!" << endl;
break;
}
}
return 0;
}

185
ProcessSync.cpp Normal file
View File

@@ -0,0 +1,185 @@
#include <iostream>
#include <thread>
#include <vector>
#include <chrono>
#include <random>
#include <semaphore>
#include <mutex>
#include <iomanip>
using namespace std;
// 缓冲区大小
const int BUFFER_SIZE = 5;
// 生产者数量
const int PRODUCER_COUNT = 3;
// 消费者数量
const int CONSUMER_COUNT = 2;
// 每个生产者生产的产品数量
const int PRODUCTS_PER_PRODUCER = 10;
// 缓冲区结构
struct Buffer {
vector<int> data; // 存储产品的数组
int in; // 生产者插入位置
int out; // 消费者取出位置
Buffer() : data(BUFFER_SIZE, 0), in(0), out(0) {}
};
// 全局变量
Buffer buffer; // 共享缓冲区
counting_semaphore<BUFFER_SIZE> empty_sem(BUFFER_SIZE); // 空缓冲区数量信号量
counting_semaphore<BUFFER_SIZE> full_sem(0); // 满缓冲区数量信号量
mutex buffer_mutex; // 缓冲区互斥锁
mutex output_mutex; // 输出互斥锁
int total_produced = 0; // 总生产数量
int total_consumed = 0; // 总消费数量
// 打印缓冲区状态的函数
void print_buffer_status(const string& operation, int thread_id, int product_id) {
lock_guard<mutex> lock(output_mutex);
cout << operation << " 线程" << thread_id << " 产品" << product_id << endl;
cout << "缓冲区状态: [";
for (int i = 0; i < BUFFER_SIZE; i++) {
if (i > 0) cout << ", ";
if ((buffer.out <= buffer.in && i >= buffer.out && i < buffer.in) ||
(buffer.out > buffer.in && (i >= buffer.out || i < buffer.in))) {
cout << buffer.data[i];
} else {
cout << "";
}
}
cout << "]" << endl;
cout << "in=" << buffer.in << ", out=" << buffer.out;
cout << ", 已生产=" << total_produced << ", 已消费=" << total_consumed << endl;
cout << "----------------------------------------" << endl;
}
// 生产者函数
void producer(int producer_id) {
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> dis(100, 999); // 生成三位数产品编号
for (int i = 0; i < PRODUCTS_PER_PRODUCER; i++) {
// 生产产品(模拟生产时间)
this_thread::sleep_for(chrono::milliseconds(dis(gen) % 500 + 100));
int product = producer_id * 1000 + i + 1; // 产品编号生产者ID*1000 + 序号
// P操作等待空缓冲区
empty_sem.acquire();
// P操作获取缓冲区互斥锁
{
lock_guard<mutex> lock(buffer_mutex);
// 将产品放入缓冲区
buffer.data[buffer.in] = product;
buffer.in = (buffer.in + 1) % BUFFER_SIZE;
total_produced++;
// 打印生产信息
print_buffer_status("生产者", producer_id, product);
}
// V操作释放满缓冲区信号量
full_sem.release();
}
{
lock_guard<mutex> lock(output_mutex);
cout << "生产者" << producer_id << " 完成所有生产任务" << endl;
}
}
// 消费者函数
void consumer(int consumer_id) {
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> dis(100, 999);
// 计算每个消费者需要消费的产品数量
int products_to_consume = (PRODUCER_COUNT * PRODUCTS_PER_PRODUCER) / CONSUMER_COUNT;
if (consumer_id < (PRODUCER_COUNT * PRODUCTS_PER_PRODUCER) % CONSUMER_COUNT) {
products_to_consume++; // 处理不能整除的情况
}
for (int i = 0; i < products_to_consume; i++) {
// P操作等待满缓冲区
full_sem.acquire();
int product;
// P操作获取缓冲区互斥锁
{
lock_guard<mutex> lock(buffer_mutex);
// 从缓冲区取出产品
product = buffer.data[buffer.out];
buffer.data[buffer.out] = 0; // 清空该位置
buffer.out = (buffer.out + 1) % BUFFER_SIZE;
total_consumed++;
// 打印消费信息
print_buffer_status("消费者", consumer_id, product);
}
// V操作释放空缓冲区信号量
empty_sem.release();
// 消费产品(模拟消费时间)
this_thread::sleep_for(chrono::milliseconds(dis(gen) % 300 + 150));
}
{
lock_guard<mutex> lock(output_mutex);
cout << "消费者" << consumer_id << " 完成所有消费任务" << endl;
}
}
int main() {
cout << "========== 多生产者多消费者多缓冲区同步实验 ==========" << endl;
cout << "缓冲区大小: " << BUFFER_SIZE << endl;
cout << "生产者数量: " << PRODUCER_COUNT << endl;
cout << "消费者数量: " << CONSUMER_COUNT << endl;
cout << "每个生产者生产产品数: " << PRODUCTS_PER_PRODUCER << endl;
cout << "总产品数量: " << PRODUCER_COUNT * PRODUCTS_PER_PRODUCER << endl;
cout << "========================================" << endl;
// 创建生产者线程
vector<thread> producers;
for (int i = 0; i < PRODUCER_COUNT; i++) {
producers.emplace_back(producer, i + 1);
}
// 创建消费者线程
vector<thread> consumers;
for (int i = 0; i < CONSUMER_COUNT; i++) {
consumers.emplace_back(consumer, i + 1);
}
// 等待所有生产者线程结束
for (auto& p : producers) {
p.join();
}
// 等待所有消费者线程结束
for (auto& c : consumers) {
c.join();
}
cout << "========== 实验结束 ==========" << endl;
cout << "最终统计:" << endl;
cout << "总生产数量: " << total_produced << endl;
cout << "总消费数量: " << total_consumed << endl;
if (total_produced == total_consumed &&
total_produced == PRODUCER_COUNT * PRODUCTS_PER_PRODUCER) {
cout << "实验成功!所有产品都被正确生产和消费。" << endl;
} else {
cout << "实验异常!生产和消费数量不匹配。" << endl;
}
return 0;
}

BIN
build/.ninja_deps Normal file

Binary file not shown.

25
build/.ninja_log Normal file
View File

@@ -0,0 +1,25 @@
# ninja log v6
6 141 7728442367360176 CMakeFiles/DeadlockAvoid.dir/DeadlockAvoid.cpp.obj.ddi 815eb603b90f847
7 148 7728442367370069 CMakeFiles/MemoryManager.dir/MemoryManager.cpp.obj.ddi c3605bb22267fbaa
3 156 7728442367330182 CMakeFiles/CPUScheduler.dir/CPUScheduler.cpp.obj.ddi 5bb1f5a2099f2054
142 166 7728442368928283 CMakeFiles/DeadlockAvoid.dir/CXX.dd a68f79387401aa36
142 166 7728442368928283 D:/Schoolwork/OperatingSystem/Experiment/build/CMakeFiles/DeadlockAvoid.dir/CXXModules.json a68f79387401aa36
142 166 7728442368928283 CMakeFiles/DeadlockAvoid.dir/DeadlockAvoid.cpp.obj.modmap a68f79387401aa36
148 168 7728442368948547 CMakeFiles/MemoryManager.dir/CXX.dd 9973a5b84b9e743f
148 168 7728442368948547 D:/Schoolwork/OperatingSystem/Experiment/build/CMakeFiles/MemoryManager.dir/CXXModules.json 9973a5b84b9e743f
148 168 7728442368948547 CMakeFiles/MemoryManager.dir/MemoryManager.cpp.obj.modmap 9973a5b84b9e743f
156 174 7728442369008260 CMakeFiles/CPUScheduler.dir/CXX.dd 93c2c369638ddac
156 174 7728442369008260 D:/Schoolwork/OperatingSystem/Experiment/build/CMakeFiles/CPUScheduler.dir/CXXModules.json 93c2c369638ddac
156 174 7728442369008260 CMakeFiles/CPUScheduler.dir/CPUScheduler.cpp.obj.modmap 93c2c369638ddac
5 220 7728442367350200 CMakeFiles/ProcessSync.dir/ProcessSync.cpp.obj.ddi d1c3ed997e1516bf
220 239 7728442369667015 CMakeFiles/ProcessSync.dir/CXX.dd 2630128d0025735c
220 239 7728442369667015 D:/Schoolwork/OperatingSystem/Experiment/build/CMakeFiles/ProcessSync.dir/CXXModules.json 2630128d0025735c
220 239 7728442369667015 CMakeFiles/ProcessSync.dir/ProcessSync.cpp.obj.modmap 2630128d0025735c
168 803 7728442368988503 CMakeFiles/MemoryManager.dir/MemoryManager.cpp.obj 6d95d073bcf8673d
167 905 7728442368968289 CMakeFiles/DeadlockAvoid.dir/DeadlockAvoid.cpp.obj 88dd95a480d09c48
174 916 7728442369050366 CMakeFiles/CPUScheduler.dir/CPUScheduler.cpp.obj e1acfffe2c4a16dd
806 926 7728442375358662 MemoryManager.exe 53c58cc242da530d
905 999 7728442376356262 DeadlockAvoid.exe 8a854c7dcb4b2f5
917 1026 7728442376466136 CPUScheduler.exe 6ec96ba2dfc6bf80
240 1402 7728442369697014 CMakeFiles/ProcessSync.dir/ProcessSync.cpp.obj 571c4449ee50ccff
1402 1488 7728442381324030 ProcessSync.exe 3901623b6c165673

305
build/build.ninja Normal file

File diff suppressed because one or more lines are too long