Skip to content

Commit 266008c

Browse files
committed
arrangement: zip_pair_matching; traversal: execute: _while, _with_index
1 parent 0362acb commit 266008c

50 files changed

Lines changed: 3286 additions & 405 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

library/logicwise/arrangement.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace logicwise::arrangement
3838

3939
using detail::cartesian_pair; //笛卡尔积对
4040
using detail::zip_pair_truncation; //截断对齐对
41+
using detail::zip_pair_matching; //匹配对齐对
4142
using detail::zip_pair_padding; //填充对齐对
4243

4344
//排布::多部 arrangement::multipartite================================================================================
@@ -46,6 +47,7 @@ namespace logicwise::arrangement
4647

4748
using detail::cartesian_tuple; //笛卡尔积多元组
4849
using detail::zip_tuple_truncation; //截断对齐多元组
50+
using detail::zip_tuple_matching; //匹配对齐多元组
4951
using detail::zip_tuple_padding; //填充对齐多元组
5052

5153
}

library/logicwise/arrangement/bipartite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
//聚合头文件
99
#include "bipartite/cartesian_pair.h"
1010
#include "bipartite/zip_pair_truncation.h"
11+
#include "bipartite/zip_pair_matching.h"
1112
#include "bipartite/zip_pair_padding.h"

library/logicwise/arrangement/bipartite/cartesian_pair.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace logicwise::detail
2323
using index_type = typename index_trait::index_type;
2424
using index_integer_type = int;
2525

26-
static constexpr std::size_t index_count(extent_type extent)
26+
static constexpr std::size_t index_count(extent_type extent) noexcept
2727
{
2828
return extent.i() * extent.j();
2929
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Logicwise
2+
// Copyright (c) 2026 Frog Singing (@frog-singing)
3+
// SPDX-License-Identifier: MIT
4+
5+
#pragma once
6+
#include <logicwise/arrangement/type.h>
7+
#include <logicwise/index/type.h>
8+
#include <logicwise/detail/extent_component_mismatch.h>
9+
#include <logicwise/detail/safe_integer_cast.h>
10+
#include <cstddef> //用于 std::size_t
11+
#include <algorithm> //用于 std::min
12+
#include <cassert> //用于 assert
13+
14+
15+
//逻辑维度::细节
16+
namespace logicwise::detail
17+
{
18+
//排布::二部 arrangement::bipartite================================================================================
19+
20+
//匹配对齐对
21+
struct zip_pair_matching : bipartite_arrangement_tag
22+
{
23+
using extent_type = Extent2D;
24+
using index_trait = IndexTrait2D;
25+
using index_type = typename index_trait::index_type;
26+
using index_integer_type = int;
27+
28+
template<extent_type Extent>
29+
static constexpr bool ValidExtent = []{
30+
static_assert(Extent.i() == Extent.j(), "[logicwise] Extent component mismatch.");
31+
return true;
32+
}();
33+
34+
static constexpr void verify_extent(extent_type extent) noexcept
35+
{
36+
if (extent.i() != extent.j()) [[unlikely]] { extent_component_mismatch(); }
37+
}
38+
39+
static constexpr std::size_t index_count(extent_type extent) noexcept
40+
{
41+
verify_extent(extent);
42+
return extent.i();
43+
}
44+
45+
struct forward_index_traverser
46+
{
47+
const index_integer_type uniform_extent;
48+
index_integer_type uniform_index{ 0 };
49+
50+
forward_index_traverser() = delete; //禁用默认构造函数
51+
52+
explicit constexpr forward_index_traverser(extent_type extent) noexcept
53+
: uniform_extent{ safe_integer_cast<index_integer_type>(extent.i()) }
54+
{
55+
verify_extent(extent);
56+
}
57+
58+
constexpr bool done() const noexcept { return uniform_index >= uniform_extent; }
59+
60+
constexpr auto state() const noexcept
61+
{
62+
assert(!done() && uniform_index >= 0 && "[logicwise] Accessing illegal index.");
63+
64+
return index_type
65+
{
66+
static_cast<std::size_t>(uniform_index),
67+
static_cast<std::size_t>(uniform_index)
68+
};
69+
}
70+
71+
constexpr void step() noexcept { ++uniform_index; }
72+
};
73+
74+
struct reverse_index_traverser
75+
{
76+
index_integer_type uniform_index;
77+
78+
reverse_index_traverser() = delete; //禁用默认构造函数
79+
80+
explicit constexpr reverse_index_traverser(extent_type extent) noexcept
81+
: uniform_index{ safe_integer_cast<index_integer_type>(extent.i()) - 1 }
82+
{
83+
verify_extent(extent);
84+
}
85+
86+
constexpr bool done() const noexcept { return uniform_index < 0; }
87+
88+
constexpr auto state() const noexcept
89+
{
90+
assert(!done() && "[logicwise] Accessing illegal index.");
91+
92+
return index_type
93+
{
94+
static_cast<std::size_t>(uniform_index),
95+
static_cast<std::size_t>(uniform_index)
96+
};
97+
}
98+
99+
constexpr void step() noexcept { --uniform_index; }
100+
};
101+
102+
using fast_index_traverser = reverse_index_traverser;
103+
using light_index_traverser = reverse_index_traverser;
104+
105+
};
106+
107+
}

library/logicwise/arrangement/bipartite/zip_pair_padding.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ namespace logicwise::detail
2424
using index_type = typename index_trait::index_type;
2525
using index_integer_type = int;
2626

27-
static constexpr std::size_t index_count(extent_type extent)
27+
static constexpr std::size_t index_count(extent_type extent) noexcept
2828
{
2929
return (std::max)(extent.i(), extent.j());
3030
}
3131

3232
struct forward_index_traverser
3333
{
3434
const index_integer_type extent_i, extent_j, max_extent;
35-
index_integer_type linear_index{ 0 };
35+
index_integer_type uniform_index{ 0 };
3636

3737
forward_index_traverser() = delete; //禁用默认构造函数
3838

@@ -42,42 +42,42 @@ namespace logicwise::detail
4242
, max_extent{ (std::max)(extent_i, extent_j) }
4343
{}
4444

45-
constexpr bool done() const noexcept { return linear_index >= max_extent; }
45+
constexpr bool done() const noexcept { return uniform_index >= max_extent; }
4646

4747
constexpr auto state() const noexcept
4848
{
49-
assert(!done() && linear_index >= 0 && "[logicwise] Accessing illegal index.");
49+
assert(!done() && uniform_index >= 0 && "[logicwise] Accessing illegal index.");
5050

5151
return index_type
5252
{
5353
{
54-
static_cast<std::size_t>(linear_index),
55-
static_cast<std::size_t>(linear_index)
54+
static_cast<std::size_t>(uniform_index),
55+
static_cast<std::size_t>(uniform_index)
5656
},
5757
{
58-
linear_index >= extent_i,
59-
linear_index >= extent_j
58+
uniform_index >= extent_i,
59+
uniform_index >= extent_j
6060
}
6161
};
6262
}
6363

64-
constexpr void step() noexcept { ++linear_index; }
64+
constexpr void step() noexcept { ++uniform_index; }
6565
};
6666

6767
struct reverse_index_traverser
6868
{
6969
const index_integer_type extent_i, extent_j;
70-
index_integer_type linear_index;
70+
index_integer_type uniform_index;
7171

7272
reverse_index_traverser() = delete; //禁用默认构造函数
7373

7474
explicit constexpr reverse_index_traverser(extent_type extent) noexcept
7575
: extent_i{ safe_integer_cast<index_integer_type>(extent.i()) }
7676
, extent_j{ safe_integer_cast<index_integer_type>(extent.j()) }
77-
, linear_index{ (std::max)(extent_i, extent_j) - 1 }
77+
, uniform_index{ (std::max)(extent_i, extent_j) - 1 }
7878
{}
7979

80-
constexpr bool done() const noexcept { return linear_index < 0; }
80+
constexpr bool done() const noexcept { return uniform_index < 0; }
8181

8282
constexpr auto state() const noexcept
8383
{
@@ -86,17 +86,17 @@ namespace logicwise::detail
8686
return index_type
8787
{
8888
{
89-
static_cast<std::size_t>(linear_index),
90-
static_cast<std::size_t>(linear_index)
89+
static_cast<std::size_t>(uniform_index),
90+
static_cast<std::size_t>(uniform_index)
9191
},
9292
{
93-
linear_index >= extent_i,
94-
linear_index >= extent_j
93+
uniform_index >= extent_i,
94+
uniform_index >= extent_j
9595
}
9696
};
9797
}
9898

99-
constexpr void step() noexcept { --linear_index; }
99+
constexpr void step() noexcept { --uniform_index; }
100100
};
101101

102102
using fast_index_traverser = reverse_index_traverser;

library/logicwise/arrangement/bipartite/zip_pair_truncation.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,62 +24,62 @@ namespace logicwise::detail
2424
using index_type = typename index_trait::index_type;
2525
using index_integer_type = int;
2626

27-
static constexpr std::size_t index_count(extent_type extent)
27+
static constexpr std::size_t index_count(extent_type extent) noexcept
2828
{
2929
return (std::min)(extent.i(), extent.j());
3030
}
3131

3232
struct forward_index_traverser
3333
{
3434
const index_integer_type min_extent;
35-
index_integer_type linear_index{ 0 };
35+
index_integer_type uniform_index{ 0 };
3636

3737
forward_index_traverser() = delete; //禁用默认构造函数
3838

3939
explicit constexpr forward_index_traverser(extent_type extent) noexcept
4040
: min_extent{ safe_integer_cast<index_integer_type>((std::min)(extent.i(), extent.j())) }
4141
{}
4242

43-
constexpr bool done() const noexcept { return linear_index >= min_extent; }
43+
constexpr bool done() const noexcept { return uniform_index >= min_extent; }
4444

4545
constexpr auto state() const noexcept
4646
{
47-
assert(!done() && linear_index >= 0 && "[logicwise] Accessing illegal index.");
47+
assert(!done() && uniform_index >= 0 && "[logicwise] Accessing illegal index.");
4848

4949
return index_type
5050
{
51-
static_cast<std::size_t>(linear_index),
52-
static_cast<std::size_t>(linear_index)
51+
static_cast<std::size_t>(uniform_index),
52+
static_cast<std::size_t>(uniform_index)
5353
};
5454
}
5555

56-
constexpr void step() noexcept { ++linear_index; }
56+
constexpr void step() noexcept { ++uniform_index; }
5757
};
5858

5959
struct reverse_index_traverser
6060
{
61-
index_integer_type linear_index;
61+
index_integer_type uniform_index;
6262

6363
reverse_index_traverser() = delete; //禁用默认构造函数
6464

6565
explicit constexpr reverse_index_traverser(extent_type extent) noexcept
66-
: linear_index{ safe_integer_cast<index_integer_type>((std::min)(extent.i(), extent.j())) - 1 }
66+
: uniform_index{ safe_integer_cast<index_integer_type>((std::min)(extent.i(), extent.j())) - 1 }
6767
{}
6868

69-
constexpr bool done() const noexcept { return linear_index < 0; }
69+
constexpr bool done() const noexcept { return uniform_index < 0; }
7070

7171
constexpr auto state() const noexcept
7272
{
7373
assert(!done() && "[logicwise] Accessing illegal index.");
7474

7575
return index_type
7676
{
77-
static_cast<std::size_t>(linear_index),
78-
static_cast<std::size_t>(linear_index)
77+
static_cast<std::size_t>(uniform_index),
78+
static_cast<std::size_t>(uniform_index)
7979
};
8080
}
8181

82-
constexpr void step() noexcept { --linear_index; }
82+
constexpr void step() noexcept { --uniform_index; }
8383
};
8484

8585
using fast_index_traverser = reverse_index_traverser;

library/logicwise/arrangement/elementwise/element.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace logicwise::detail
3535
using index_type = typename index_trait::index_type;
3636
using index_integer_type = int;
3737

38-
static constexpr std::size_t index_count(extent_type extent)
38+
static constexpr std::size_t index_count(extent_type extent) noexcept
3939
{
4040
return extent.i();
4141
}

library/logicwise/arrangement/multipartite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
//聚合头文件
99
#include "multipartite/cartesian_tuple.h"
1010
#include "multipartite/zip_tuple_truncation.h"
11+
#include "multipartite/zip_tuple_matching.h"
1112
#include "multipartite/zip_tuple_padding.h"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Logicwise
2+
// Copyright (c) 2026 Frog Singing (@frog-singing)
3+
// SPDX-License-Identifier: MIT
4+
5+
#pragma once
6+
#include <logicwise/arrangement/type.h>
7+
#include <logicwise/index/type.h>
8+
#include <logicwise/detail/safe_integer_cast.h>
9+
#include <cstddef> //用于 std::size_t
10+
#include <cassert> //用于 assert
11+
12+
13+
namespace logicwise::detail
14+
{
15+
struct zip_tuple_matching;
16+
17+
template<std::size_t Arity>
18+
struct zip_tuple_matching_impl;
19+
}
20+
21+
22+
//逻辑维度::细节
23+
namespace logicwise::detail
24+
{
25+
//排布::多部 arrangement::multipartite================================================================================
26+
27+
//匹配对齐多元组
28+
struct zip_tuple_matching : multipartite_arrangement_tag
29+
{
30+
template<std::size_t Arity>
31+
using arrangement = zip_tuple_matching_impl<Arity>;
32+
};
33+
34+
template<std::size_t Arity>
35+
struct zip_tuple_matching_impl
36+
{
37+
using extent_type = Extent<Arity>;
38+
using index_trait = IndexTrait<Arity>;
39+
using index_type = typename index_trait::index_type;
40+
using index_integer_type = int;
41+
42+
43+
44+
/*
45+
template<extent_type Extent>
46+
static constexpr bool ValidExtent = []{
47+
static_assert(Extent.i() == Extent.j(), "[logicwise] Extent component mismatch.");
48+
return true;
49+
}();
50+
*/
51+
52+
53+
//使用 const extent_type&
54+
//使用 const index_type&
55+
};
56+
57+
}

0 commit comments

Comments
 (0)