Merge pull request #3745 from egorpugin/main

Remove unused functions in genericvector.h.
This commit is contained in:
Stefan Weil 2022-02-06 23:13:03 +01:00 committed by GitHub
commit 4ce8fafd82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,10 +41,6 @@ public:
GenericVector() {
init(kDefaultVectorSize);
}
GenericVector(int size, const T &init_val) {
init(size);
init_to_size(size, init_val);
}
// Copy
GenericVector(const GenericVector &other) {
@ -107,14 +103,6 @@ public:
int push_back(T object);
void operator+=(const T &t);
// Push an element in the end of the array if the same
// element is not already contained in the array.
int push_back_new(const T &object);
// Push an element in the front of the array
// Note: This function is O(n)
int push_front(const T &object);
// Set the value at the given index
void set(const T &t, int index);
@ -178,27 +166,13 @@ public:
// bool T::Serialize(FILE* fp) const that returns false in case of error.
// Returns false in case of error.
bool SerializeClasses(FILE *fp) const;
bool SerializeClasses(TFile *fp) const;
// Reads a vector of classes from the given file. Assumes the existence of
// bool T::Deserialize(bool swap, FILE* fp) that returns false in case of
// error. Also needs T::T() and T::T(constT&), as init_to_size is used in
// this function. Returns false in case of error.
// If swap is true, assumes a big/little-endian swap is needed.
bool DeSerializeClasses(bool swap, FILE *fp);
bool DeSerializeClasses(TFile *fp);
// Allocates a new array of double the current_size, copies over the
// information from data to the new location, deletes data and returns
// the pointed to the new larger array.
// This function uses memcpy to copy the data, instead of invoking
// operator=() for each element like double_the_size() does.
static T *double_the_size_memcpy(int current_size, T *data) {
T *data_new = new T[current_size * 2];
memcpy(data_new, data, sizeof(T) * current_size);
delete[] data;
return data_new;
}
// Reverses the elements of the vector.
void reverse() {
for (int i = 0; i < size_used_ / 2; ++i) {
@ -221,26 +195,6 @@ public:
qsort(data_, size_used_, sizeof(*data_), comparator);
}
// Searches the array (assuming sorted in ascending order, using sort()) for
// an element equal to target and returns the index of the best candidate.
// The return value is conceptually the largest index i such that
// data_[i] <= target or 0 if target < the whole vector.
// NOTE that this function uses operator> so really the return value is
// the largest index i such that data_[i] > target is false.
int binary_search(const T &target) const {
int bottom = 0;
int top = size_used_;
while (top - bottom > 1) {
int middle = (bottom + top) / 2;
if (data_[middle] > target) {
top = middle;
} else {
bottom = middle;
}
}
return bottom;
}
// Swaps the elements with the given indices.
void swap(int index1, int index2) {
if (index1 != index2) {
@ -307,11 +261,6 @@ inline bool SaveDataToFile(const GenericVector<char> &data, const char *filename
return result;
}
template <typename T>
bool cmp_eq(T const &t1, T const &t2) {
return t1 == t2;
}
// Used by sort()
// return < 0 if t1 < t2
// return 0 if t1 == t2
@ -632,29 +581,6 @@ int GenericVector<T>::push_back(T object) {
return index;
}
template <typename T>
int GenericVector<T>::push_back_new(const T &object) {
int index = get_index(object);
if (index >= 0) {
return index;
}
return push_back(object);
}
// Add an element in the array (front)
template <typename T>
int GenericVector<T>::push_front(const T &object) {
if (size_used_ == size_reserved_) {
double_the_size();
}
for (int i = size_used_; i > 0; --i) {
data_[i] = data_[i - 1];
}
data_[0] = object;
++size_used_;
return 0;
}
template <typename T>
void GenericVector<T>::operator+=(const T &t) {
push_back(t);
@ -831,18 +757,6 @@ bool GenericVector<T>::SerializeClasses(FILE *fp) const {
}
return true;
}
template <typename T>
bool GenericVector<T>::SerializeClasses(TFile *fp) const {
if (fp->FWrite(&size_used_, sizeof(size_used_), 1) != 1) {
return false;
}
for (int i = 0; i < size_used_; ++i) {
if (!data_[i].Serialize(fp)) {
return false;
}
}
return true;
}
// Reads a vector of classes from the given file. Assumes the existence of
// bool T::Deserialize(bool swap, FILE* fp) that returns false in case of
@ -850,24 +764,6 @@ bool GenericVector<T>::SerializeClasses(TFile *fp) const {
// this function. Returns false in case of error.
// If swap is true, assumes a big/little-endian swap is needed.
template <typename T>
bool GenericVector<T>::DeSerializeClasses(bool swap, FILE *fp) {
int32_t reserved;
if (fread(&reserved, sizeof(reserved), 1, fp) != 1) {
return false;
}
if (swap) {
Reverse32(&reserved);
}
T empty;
init_to_size(reserved, empty);
for (int i = 0; i < reserved; ++i) {
if (!data_[i].DeSerialize(swap, fp)) {
return false;
}
}
return true;
}
template <typename T>
bool GenericVector<T>::DeSerializeClasses(TFile *fp) {
int32_t reserved;
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) {