Skip to content

Commit

Permalink
bitset功能替换bitarray
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed May 22, 2024
1 parent 9172eee commit 3ab2500
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 335 deletions.
2 changes: 1 addition & 1 deletion extend/lcodec/lcodec.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\bitarray.h" />
<ClInclude Include="src\bitset.h" />
<ClInclude Include="src\guid.h" />
<ClInclude Include="src\hash.h" />
<ClInclude Include="src\http.h" />
Expand Down
2 changes: 1 addition & 1 deletion extend/lcodec/lcodec.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClInclude Include="src\bitarray.h">
<ClInclude Include="src\bitset.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\guid.h">
Expand Down
262 changes: 0 additions & 262 deletions extend/lcodec/src/bitarray.h

This file was deleted.

51 changes: 51 additions & 0 deletions extend/lcodec/src/bitset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include <bitset>
#include <string>
#include <stdlib.h>

namespace lcodec {

template <std::size_t N>
std::string lua_bitset_new(std::string val) {
std::bitset<N> bit(val);
return bit.to_string();
}

template <std::size_t N>
bool lua_bitset_get(std::string val, size_t pos) {
std::bitset<N> bit(val);
return bit[pos - 1];
}

template <std::size_t N>
std::string lua_bitset_set(std::string val, size_t pos, bool bval) {
std::bitset<N> bit(val);
return bit.set(pos - 1, bval).to_string();
}

template <std::size_t N>
std::string lua_bitset_flip(std::string val, size_t pos) {
std::bitset<N> bit(val);
return bit.flip(pos - 1).to_string();
}

template <std::size_t N>
std::string lua_bitset_reset(std::string val, size_t pos) {
std::bitset<N> bit(val);
if (pos == 0) {
return bit.reset().to_string();
}
return bit.reset(pos - 1).to_string();
}

template <std::size_t N>
bool lua_bitset_check(std::string val, size_t len) {
if (len > N) return false;
std::bitset<N> bit(val);
for (size_t i = 0; i < len; ++i) {
if (!bit[i]) return false;
}
return true;
}
}
Loading

0 comments on commit 3ab2500

Please sign in to comment.