Page Menu
Home
Search
Configure Global Search
Log In
Paste
P2907
any kind of c++ sort would crash here?
Active
Public
Actions
Authored by
YimingWu (NicksBest)
on Apr 25 2022, 12:27 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Tags
None
Subscribers
None
//-------------------------------------
typedef
struct
LineartAdjacentItem
{
unsigned
int
v1
;
unsigned
int
v2
;
unsigned
int
e
;
}
LineartAdjacentItem
;
//-------------------------------------
static
int
cmp_adjacent_items
(
const
LineartAdjacentItem
&
p1
,
const
LineartAdjacentItem
&
p2
)
{
int
a
=
(
int
)
p1
.
v1
-
(
int
)
p2
.
v1
;
int
b
=
(
int
)
p1
.
v2
-
(
int
)
p2
.
v2
;
return
a
?
a
:
b
;
}
void
lineart_sort_adjacent_items
(
LineartAdjacentItem
*
ai
,
int
length
)
{
blender
::
Vector
<
LineartAdjacentItem
>
_ai
;
_ai
.
reserve
(
length
);
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
_ai
[
i
]
=
ai
[
i
];
printf
(
"(%d %d %d)"
,
_ai
[
i
].
v1
,
_ai
[
i
].
v2
,
_ai
[
i
].
e
);
}
_ai
.
resize
(
length
);
printf
(
"
\n
"
);
// No matter which version you use it doesn't work.
// techically _ai.begin() and _ai.end() does get the correct address offset like ai, ai + length
blender
::
parallel_sort
(
_ai
.
begin
(),
_ai
.
end
(),
cmp_adjacent_items
);
// blender::parallel_sort(ai, ai + length, cmp_adjacent_items);
// std::sort(_ai.begin(), _ai.end(), cmp_adjacent_items);
// std::sort(ai, ai + length, cmp_adjacent_items);
for
(
int
i
=
0
;
i
<
length
;
i
++
)
{
ai
[
i
]
=
_ai
[
i
];
printf
(
"(%d %d %d)"
,
_ai
[
i
].
v1
,
_ai
[
i
].
v2
,
_ai
[
i
].
e
);
}
}
//-------------------------------------
// This is how I call it: (total_edges == length(ai))
// This doesn't work.
lineart_sort_adjacent_items
(
ai
,
total_edges
);
// This works out of box.
// qsort(ai, total_edges, sizeof(LineartAdjacentItem), cmp_adjacent_items);
Event Timeline
YimingWu (NicksBest)
created this paste.
Apr 25 2022, 12:27 PM
Log In to Comment