Skip to content

Commit ffd0195

Browse files
authored
Merge pull request #264 from DeciSym/263-clang-format-libdcs
#263 - Executed clang-format on the .h and .cpp files with defaults
2 parents cc90812 + 8ac1921 commit ffd0195

20 files changed

Lines changed: 3663 additions & 3754 deletions

libhdt/src/libdcs/CSD.cpp

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,67 +30,61 @@
3030
* Rodrigo Canovas: rcanovas@dcc.uchile.cl
3131
* Miguel A. Martinez-Prieto: migumar2@infor.uva.es
3232
*/
33-
#include <stdexcept>
3433
#include "CSD.h"
3534
#include "CSD_PFC.h"
35+
#include <stdexcept>
3636

3737
#ifdef HAVE_CDS
38-
#include "CSD_HTFC.h"
3938
#include "CSD_FMIndex.h"
39+
#include "CSD_HTFC.h"
4040

4141
#include <libcdsBasics.h>
4242

4343
using namespace cds_utils;
4444

4545
#endif
4646

47-
namespace csd
48-
{
47+
namespace csd {
4948

50-
CSD::CSD() : numstrings(0) {
49+
CSD::CSD() : numstrings(0) {}
5150

52-
}
53-
54-
CSD * CSD::load(istream & fp)
55-
{
56-
int type = fp.get();
57-
if(!fp.good()) {
58-
throw std::runtime_error("Error reading stream");
59-
}
60-
switch(type)
61-
{
62-
case PFC:
63-
return CSD_PFC::load(fp);
51+
CSD *CSD::load(istream &fp) {
52+
int type = fp.get();
53+
if (!fp.good()) {
54+
throw std::runtime_error("Error reading stream");
55+
}
56+
switch (type) {
57+
case PFC:
58+
return CSD_PFC::load(fp);
6459
#ifdef HAVE_CDS
65-
case FMINDEX:
66-
return CSD_FMIndex::load(fp);
67-
case HTFC:
68-
return CSD_HTFC::load(fp);
60+
case FMINDEX:
61+
return CSD_FMIndex::load(fp);
62+
case HTFC:
63+
return CSD_HTFC::load(fp);
6964
#endif
70-
default:
71-
throw std::logic_error("No implementation for CSD");
72-
}
73-
return NULL;
65+
default:
66+
throw std::logic_error("No implementation for CSD");
67+
}
68+
return NULL;
7469
}
7570

76-
CSD *CSD::create(unsigned char type)
77-
{
78-
switch(type)
79-
{
80-
case PFC: return new CSD_PFC();
71+
CSD *CSD::create(unsigned char type) {
72+
switch (type) {
73+
case PFC:
74+
return new CSD_PFC();
8175
#ifdef HAVE_CDS
82-
case HTFC: return new CSD_HTFC();
83-
case FMINDEX: return new CSD_FMIndex();
76+
case HTFC:
77+
return new CSD_HTFC();
78+
case FMINDEX:
79+
return new CSD_FMIndex();
8480
#endif
85-
default: throw std::logic_error("No implementation for CSD");
86-
}
81+
default:
82+
throw std::logic_error("No implementation for CSD");
83+
}
8784

88-
return NULL;
85+
return NULL;
8986
}
9087

91-
size_t CSD::getLength()
92-
{
93-
return numstrings;
94-
}
88+
size_t CSD::getLength() { return numstrings; }
9589

96-
}
90+
} // namespace csd

libhdt/src/libdcs/CSD.h

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* ==========================================================================
88
* "Compressed String Dictionaries"
9-
* Nieves R. Brisaboa, Rodrigo Canovas, Francisco Claude,
9+
* Nieves R. Brisaboa, Rodrigo Canovas, Francisco Claude,
1010
* Miguel A. Martinez-Prieto and Gonzalo Navarro.
1111
* 10th Symposium on Experimental Algorithms (SEA'2011), p.136-147, 2011.
1212
* ==========================================================================
@@ -34,81 +34,83 @@
3434
#ifndef _COMPRESSEDSTRINGDICTIONARY_H
3535
#define _COMPRESSEDSTRINGDICTIONARY_H
3636

37-
#include <stdint.h>
3837
#include <Iterator.hpp>
39-
#include <iostream>
4038
#include <cassert>
39+
#include <iostream>
40+
#include <stdint.h>
4141
#include <vector>
4242
using namespace std;
4343

44-
namespace csd
45-
{
44+
namespace csd {
4645
static const uint32_t PFC = 2;
4746
static const uint32_t HTFC = 3;
4847
static const uint32_t FMINDEX = 4;
4948
static const uint32_t REPAIRDAC = 5;
5049
static const uint32_t HASHHUFF = 6;
5150

52-
class CSD
53-
{
54-
public:
55-
CSD();
56-
/** General destructor */
57-
virtual ~CSD() {};
51+
class CSD {
52+
public:
53+
CSD();
54+
/** General destructor */
55+
virtual ~CSD(){};
56+
57+
/** Returns the ID that identify s[1..length]. If it does not exist,
58+
returns 0.
59+
@s: the string to be located.
60+
@len: the length (in characters) of the string s.
61+
*/
62+
virtual size_t locate(const unsigned char *s, size_t len) = 0;
5863

59-
/** Returns the ID that identify s[1..length]. If it does not exist,
60-
returns 0.
61-
@s: the string to be located.
62-
@len: the length (in characters) of the string s.
63-
*/
64-
virtual size_t locate(const unsigned char *s, size_t len)=0;
64+
/** Returns the string identified by id.
65+
@id: the identifier to be extracted.
66+
*/
67+
virtual unsigned char *extract(size_t id) = 0;
6568

66-
/** Returns the string identified by id.
67-
@id: the identifier to be extracted.
68-
*/
69-
virtual unsigned char * extract(size_t id)=0;
69+
/**
70+
* Free the string returned by extract()
71+
*/
72+
virtual void freeString(const unsigned char *) = 0;
7073

71-
/**
72-
* Free the string returned by extract()
73-
*/
74-
virtual void freeString(const unsigned char *)=0;
74+
/** Returns the size of the structure in bytes. */
75+
virtual uint64_t getSize() = 0;
7576

76-
/** Returns the size of the structure in bytes. */
77-
virtual uint64_t getSize()=0;
77+
virtual hdt::IteratorUCharString *listAll() = 0;
7878

79-
virtual hdt::IteratorUCharString *listAll()=0;
79+
/** Returns the number of strings in the dictionary. */
80+
size_t getLength();
8081

81-
/** Returns the number of strings in the dictionary. */
82-
size_t getLength();
82+
// Search for terms by prefix. It returns a vector of a given maximum size
83+
// "maxResults"
84+
virtual void fillSuggestions(const char *prefix, vector<string> &out,
85+
int maxResults) = 0;
8386

84-
// Search for terms by prefix. It returns a vector of a given maximum size "maxResults"
85-
virtual void fillSuggestions(const char *prefix, vector<string> &out, int maxResults)=0;
87+
// Search for terms by prefix. It returns an iterator of all results in the
88+
// dictionary
89+
virtual hdt::IteratorUCharString *getSuggestions(const char *prefix) = 0;
8690

87-
// Search for terms by prefix. It returns an iterator of all results in the dictionary
88-
virtual hdt::IteratorUCharString *getSuggestions(const char *prefix)=0;
91+
// Search for terms by prefix. It returns an iterator of all results in the
92+
// dictionary, by ID
93+
virtual hdt::IteratorUInt *getIDSuggestions(const char *prefix) = 0;
8994

90-
// Search for terms by prefix. It returns an iterator of all results in the dictionary, by ID
91-
virtual hdt::IteratorUInt *getIDSuggestions(const char *prefix)=0;
95+
/** Stores a CSD structure given a file pointer.
96+
@fp: pointer to the file saving a CSD structure.
97+
*/
98+
virtual void save(ostream &fp) = 0;
9299

93-
/** Stores a CSD structure given a file pointer.
94-
@fp: pointer to the file saving a CSD structure.
95-
*/
96-
virtual void save(ostream & fp)=0;
100+
virtual size_t load(unsigned char *ptr, unsigned char *ptrMax) = 0;
97101

98-
virtual size_t load(unsigned char *ptr, unsigned char *ptrMax)=0;
102+
/** Loads a CSD structure from a file pointer.
103+
@fp: pointer to the file storing a CSD structure. */
104+
static CSD *load(istream &fp);
99105

100-
/** Loads a CSD structure from a file pointer.
101-
@fp: pointer to the file storing a CSD structure. */
102-
static CSD * load(istream & fp);
106+
static CSD *create(unsigned char type);
103107

104-
static CSD * create(unsigned char type);
105-
106-
protected:
107-
unsigned char type; //! Dictionary type.
108-
size_t tlength; //! Original Tdict size.
109-
size_t numstrings; //! Number of elements in the dictionary.
110-
};
108+
protected:
109+
unsigned char type; //! Dictionary type.
110+
size_t tlength; //! Original Tdict size.
111+
size_t numstrings; //! Number of elements in the dictionary.
112+
};
111113

112-
}
114+
} // namespace csd
113115

114-
#endif
116+
#endif

libhdt/src/libdcs/CSD_Cache.cpp

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,21 @@
2727

2828
#include <stdlib.h>
2929

30-
#include <string.h>
3130
#include "CSD_Cache.h"
31+
#include <string.h>
3232

33-
namespace csd
34-
{
35-
CSD_Cache::CSD_Cache(CSD *child) : child(child)//, cacheint(65536), cachestr(1024)
33+
namespace csd {
34+
CSD_Cache::CSD_Cache(CSD *child)
35+
: child(child) //, cacheint(65536), cachestr(1024)
3636
{
37-
assert(child);
38-
numstrings = child->getLength();
37+
assert(child);
38+
numstrings = child->getLength();
3939
}
4040

41+
CSD_Cache::~CSD_Cache() { delete child; }
4142

42-
CSD_Cache::~CSD_Cache()
43-
{
44-
delete child;
45-
}
46-
47-
size_t CSD_Cache::locate(const unsigned char *s, size_t len)
48-
{
49-
// FIXME: Not working.
43+
size_t CSD_Cache::locate(const unsigned char *s, size_t len) {
44+
// FIXME: Not working.
5045
#if 0
5146
LRU_Str::const_iterator it = cachestr.find((char *)s);
5247

@@ -62,50 +57,39 @@ size_t CSD_Cache::locate(const unsigned char *s, size_t len)
6257
return value;
6358
}
6459
#endif
65-
return child->locate(s, len);
60+
return child->locate(s, len);
6661
}
6762

68-
69-
unsigned char* CSD_Cache::extract(size_t id)
70-
{
71-
return child->extract(id);
72-
/*
73-
try {
74-
const string &value = cacheint.get(id);
75-
size_t len = value.length();
76-
unsigned char *ptr = (unsigned char *)malloc((1+len)*sizeof(unsigned char));
77-
strncpy((char *)ptr, (const char *)value.c_str(), len);
78-
ptr[len]='\0';
79-
return ptr;
80-
}catch(std::range_error& e) {
81-
// Key not found: compute and insert the value
82-
char *value = (char *) child->extract(id);
83-
84-
string str(value);
85-
cacheint.put(id,str);
86-
87-
return (unsigned char *)value;
88-
}
89-
*/
63+
unsigned char *CSD_Cache::extract(size_t id) {
64+
return child->extract(id);
65+
/*
66+
try {
67+
const string &value = cacheint.get(id);
68+
size_t len = value.length();
69+
unsigned char *ptr = (unsigned char *)malloc((1+len)*sizeof(unsigned
70+
char)); strncpy((char *)ptr, (const char *)value.c_str(), len);
71+
ptr[len]='\0';
72+
return ptr;
73+
}catch(std::range_error& e) {
74+
// Key not found: compute and insert the value
75+
char *value = (char *) child->extract(id);
76+
77+
string str(value);
78+
cacheint.put(id,str);
79+
80+
return (unsigned char *)value;
81+
}
82+
*/
9083
}
9184

9285
void CSD_Cache::freeString(const unsigned char *str) {
93-
// Do nothing.
86+
// Do nothing.
9487
}
9588

96-
uint64_t CSD_Cache::getSize()
97-
{
98-
return child->getSize();
99-
}
89+
uint64_t CSD_Cache::getSize() { return child->getSize(); }
10090

101-
void CSD_Cache::save(ostream &fp)
102-
{
103-
child->save(fp);
104-
}
91+
void CSD_Cache::save(ostream &fp) { child->save(fp); }
10592

106-
CSD* CSD_Cache::load(istream &fp)
107-
{
108-
throw std::logic_error("Not imlemented");
109-
}
93+
CSD *CSD_Cache::load(istream &fp) { throw std::logic_error("Not imlemented"); }
11094

111-
}
95+
} // namespace csd

0 commit comments

Comments
 (0)