Skip to content

Commit

Permalink
修改位运算bug
Browse files Browse the repository at this point in the history
  • Loading branch information
aurshine committed Nov 23, 2024
1 parent b472de1 commit a5f4528
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
12 changes: 6 additions & 6 deletions aurshine/ayr/Dict.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ namespace ayr

self result((std::min)(capacity(), other.capacity()));
for (auto&& kv : *this)
if (contains(kv.key()))
if (other.contains(kv.key()))
result.insert_impl(kv.key(), kv.value(), ayrhash(kv.key()));

return result;
Expand All @@ -225,9 +225,7 @@ namespace ayr
self& operator&= (const self& other)
{
if (this == &other) return *this;
for (auto&& kv : other)
if (contains(kv.key()))
insert(kv.key(), kv.value(), ayrhash(kv.key()));
*this = *this & other;
return *this;
}

Expand All @@ -241,7 +239,7 @@ namespace ayr
result.insert_impl(kv.key(), kv.value(), ayrhash(kv.key()));

for (auto&& kv : other)
result.insert(kv.key(), kv.value(), ayrhash(kv.key()));
result.insert(kv.key(), kv.value());

return result;
}
Expand All @@ -251,7 +249,7 @@ namespace ayr
if (this == &other) return *this;

for (auto&& kv : other)
insert(kv.key(), kv.value(), ayrhash(kv.key()));
insert(kv.key(), kv.value());

return *this;
}
Expand Down Expand Up @@ -283,6 +281,8 @@ namespace ayr
for (auto&& kv : other)
if (contains(kv.key()))
pop(kv.key());
else
insert_impl(kv.key(), kv.value(), ayrhash(kv.key()));

return *this;
}
Expand Down
24 changes: 11 additions & 13 deletions aurshine/ayr/Set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,35 @@ namespace ayr
self operator& (const self& other) const
{
if (this == &other)
return this;
return *this;
else if (size() > other.size())
return other & *this;

self result((std::max)(capacity(), other.capacity()));
for (auto&& v : *this)
if (other.contains(v))
result.insert_impl(v);
result.insert_impl(v, ayrhash(v));

return result;
}

self& operator&=(const self& other)
{
if (this == &other) return *this;
for (auto&& v : other)
if (contains(v))
pop(v);
*this = *this & other;
return *this;
}

self operator| (const self& other) const
{
if (this == &other)
return this;
return *this;
else if (size() < other.size())
return other | *this;

self result(static_cast<c_size>((size() + other.size()) / MAX_LOAD_FACTOR));
for (auto&& v : *this)
result.insert_impl(v);
result.insert_impl(v, ayrhash(v));

for (auto&& v : other)
result.insert(v);
Expand All @@ -131,11 +129,11 @@ namespace ayr
self result(static_cast<c_size>(size() / MAX_LOAD_FACTOR));
for (auto&& v : *this)
if (!other.contains(v))
result.insert_impl(v);
result.insert_impl(v, ayrhash(v));

for (auto&& v : other)
if (!contains(v))
result.insert_impl(v);
result.insert_impl(v, ayrhash(v));

return result;
}
Expand All @@ -145,14 +143,14 @@ namespace ayr
if (this == &other)
{
clear();
return this;
return *this;
}

for (auto&& v : other)
if (contains(v))
pop(v);
else
insert_impl(v);
insert_impl(v, ayrhash(v));

return *this;
}
Expand All @@ -175,7 +173,7 @@ namespace ayr
self result(capacity());
for (auto&& v : *this)
if (!other.contains(v))
result.insert_impl(v);
result.insert_impl(v, ayrhash(v));

return result;
}
Expand All @@ -185,7 +183,7 @@ namespace ayr
if (this == &other)
{
clear();
return this;
return *this;
}

for (auto&& v : other)
Expand Down

0 comments on commit a5f4528

Please sign in to comment.