Respect infinite sized elements. Use STL's sort algorithm and not my own bubble sort.

This commit is contained in:
Moritz Bunkus 2005-06-04 09:32:33 +00:00
parent 03adf4296b
commit 9b8d9f1f0b

View File

@ -30,6 +30,7 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <algorithm>
#include <iostream> #include <iostream>
#include <typeinfo> #include <typeinfo>
@ -291,10 +292,10 @@ parse_args(vector<string> args,
// {{{ is_global, parse_multicomment/chapter_atom, asctime_r, gmtime_r // {{{ is_global, parse_multicomment/chapter_atom, asctime_r, gmtime_r
#define fits_parent(l, p) (l->GetElementPosition() < \ #define in_parent(p) \
(p->GetElementPosition() + p->ElementSize())) (!p->IsFiniteSize() || \
#define in_parent(p) (in->getFilePointer() < \ (in->getFilePointer() < \
(p->GetElementPosition() + p->ElementSize())) (p->GetElementPosition() + p->HeadSize() + p->GetSize())))
bool bool
is_global(EbmlStream *es, is_global(EbmlStream *es,
@ -346,32 +347,34 @@ asctime_r(const struct tm *tm,
// }}} // }}}
struct master_sorter_t {
int m_index;
int64_t m_pos;
inline master_sorter_t(int index, int64_t pos):
m_index(index), m_pos(pos) { }
inline bool operator <(const master_sorter_t &cmp) const {
return m_pos < cmp.m_pos;
}
};
void void
sort_master(EbmlMaster &m) { sort_master(EbmlMaster &m) {
int i, sp_idx; int i;
vector<EbmlElement *> tmp; vector<EbmlElement *> tmp;
int64_t smallest_pos; vector<master_sorter_t> sort_me;
EbmlMaster *m2;
while (m.ListSize() > 0) { for (i = 0; m.ListSize() > i; ++i)
sp_idx = 0; sort_me.push_back(master_sorter_t(i, m[i]->GetElementPosition()));
smallest_pos = m[0]->GetElementPosition(); sort(sort_me.begin(), sort_me.end());
for (i = 1; i < m.ListSize(); i++) for (i = 0; sort_me.size() > i; ++i)
if (m[i]->GetElementPosition() < smallest_pos) { tmp.push_back(m[sort_me[i].m_index]);
sp_idx = i; m.RemoveAll();
smallest_pos = m[i]->GetElementPosition();
}
tmp.push_back(m[sp_idx]); for (i = 0; tmp.size() > i; ++i)
m.Remove(sp_idx);
}
for (i = 0; i < tmp.size(); i++) {
m.PushElement(*tmp[i]); m.PushElement(*tmp[i]);
if ((m2 = dynamic_cast<EbmlMaster *>(tmp[i])) != NULL)
sort_master(*m2);
}
} }
void void