Opened 14 years ago

Closed 13 years ago

#2423 closed Bugs (fixed)

map_array insert has invalid assertion

Reported by: benson margulies <bimargulies@…> Owned by: Gunter
Milestone: Boost 1.39.0 Component: uBLAS
Version: Boost 1.36.0 Severity: Problem
Keywords: Cc:

Description

The external logic check in here appears to be wrong. The check is applied when the code sees the need to insert a new element in the underlying representation 'in the middle' -- the lower bound does not return end, and and the slot it returns does not have the correct index. The check requires the map to be empty or that the iterator is at the end, thus refusing to insert into the middle.

Form Unique Associative Container concept

BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it. std::pair<iterator,bool> insert (const value_type &p) {

iterator it = detail::lower_bound (begin (), end (), p, detail::less_pair<value_type> ()); if (it != end () && it->first == p.first)

return std::make_pair (it, false);

difference_type n = it - begin ();

BOOST_UBLAS_CHECK (size () == 0
size () == size_type (n), external_logic ());

resize (size () + 1); it = begin () + n; allow for invalidation std::copy_backward (it, end () - 1, end ()); *it = p; return std::make_pair (it, true);

}

Change History (5)

in reply to:  description comment:1 by Gunter, 14 years ago

Status: newassigned

Replying to benson margulies <bimargulies@gmail.com>:

The external logic check in here appears to be wrong. The check is applied when the code sees the need to insert a new element in the underlying representation 'in the middle' -- the lower bound does not return end, and and the slot it returns does not have the correct index. The check requires the map to be empty or that the iterator is at the end, thus refusing to insert into the middle.

I see your point. Can you provide an example where the check fails although it should succeed?

(BTW: No one seems to use map_array any more because std::map can be used instead.)

comment:2 by benson margulies <bimargulies@…>, 14 years ago

I'm reasonably certain that all you have to do is insert out of order: 1, 10, 5. If that doesn't cooperate for you, I'll cook you a test case?

std::map has incredibly slow performance for iteration. If, like me, you need to rapidly iterate over the occupied slots of the sparse data structure, std::map is awful.

comment:3 by Gunter, 14 years ago

(In [49578]) see #2423. removed the check because it makes absolutely no sense TODO: check the strange "optimization" of lower bound.

comment:4 by Gunter, 14 years ago

Milestone: Boost 1.37.0Boost 1.39.0

merged changes into release branch

comment:5 by Gunter, 13 years ago

Resolution: fixed
Status: assignedclosed

The fix seems to work without side effects. Thus I close this issue.

Note: See TracTickets for help on using tickets.