本文整理汇总了C++中Alphabet类的典型用法代码示例。如果您正苦于以下问题:C++ Alphabet类的具体用法?C++ Alphabet怎么用?C++ Alphabet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Alphabet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testOperatorNotEqual
void ComposedElementTest::testOperatorNotEqual() {
// initializes alphabet
Alphabet cho;
cho.push_back(*hydrogen);
cho.push_back(*carbon);
cho.push_back(*oxygen);
// initializes elements
Element elementH(*hydrogen);
Element elementO(*oxygen);
Element elementC(*carbon);
elements_container elements;
elements[elementH] = 4;
elements[elementO] = 2;
elements[elementC] = 2;
// checks case with different elements
composed_element_type molecule1(elements);
elements[elementH] = 5;
composed_element_type molecule1_not_equal(elements);
CPPUNIT_ASSERT(molecule1 != molecule1_not_equal);
// checks case with different sequences
composed_element_type molecule3("C2H4O2", cho),
molecule3_not_equal("C2H3O2", cho);
CPPUNIT_ASSERT(molecule3 != molecule3_not_equal);
}
示例2: testUpdateIsotopeDistribution
void ComposedElementTest::testUpdateIsotopeDistribution() {
Alphabet cho;
cho.push_back(*hydrogen);
cho.push_back(*carbon);
cho.push_back(*oxygen);
std::vector<unsigned int> decomposition;
decomposition.push_back(static_cast<unsigned int>(4));
decomposition.push_back(static_cast<unsigned int>(2));
decomposition.push_back(static_cast<unsigned int>(2));
// initializes molecule without setting isotope distribution and sequence
composed_element_type molecule(decomposition, cho);
molecule.updateIsotopeDistribution();
isotopes_type isodistr = molecule.getIsotopeDistribution();
CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getMass(0), static_cast<mass_type>(60.02113), 1.0e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getMass(1), static_cast<mass_type>(61.0245862), 1.0e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getMass(2), static_cast<mass_type>(62.0254827), 1.0e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getMass(3), static_cast<mass_type>(63.0288285), 1.0e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getAbundance(0), static_cast<abundance_type>(0.972690002), 1.0e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getAbundance(1), static_cast<abundance_type>(0.0231608083), 1.0e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getAbundance(2), static_cast<abundance_type>(0.00405304857), 1.0e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(isodistr.getAbundance(3), static_cast<abundance_type>(9.1561898e-05), 1.0e-6);
}
示例3: testOperatorEqual
void ComposedElementTest::testOperatorEqual() {
// checks for type of constructors with sequence
Alphabet cho;
cho.push_back(*hydrogen);
cho.push_back(*carbon);
cho.push_back(*oxygen);
composed_element_type molecule1("H4C2O2", cho);
composed_element_type molecule1_equal("H4C2O2", cho);
CPPUNIT_ASSERT(molecule1 == molecule1_equal);
// checks for type of constructors with elements
Element elementH(*hydrogen);
Element elementO(*oxygen);
Element elementC(*carbon);
elements_container elements;
elements[elementH] = 4;
elements[elementO] = 2;
elements[elementC] = 2;
// checks for type of constructors with elements and random sequence order
composed_element_type molecule2(elements);
composed_element_type molecule2_equal(elements);
CPPUNIT_ASSERT(molecule2 == molecule2_equal);
}
示例4:
// ----------------------------------------------
// PLAIN DECODER
// ----------------------------------------------
SegmentDecoder::SegmentDecoder(
Model *model,
int agenda) {
this->m_Model = model;
this->m_Agenda = agenda;
Alphabet *labelAlpha = model->getAlphabet("LABELS");
this->m_NumLabels = labelAlpha->size();
m_Legal = new int *[m_NumLabels + 1];
for (int i = 0; i <= m_NumLabels; ++ i) {
char prev = 'X';
if (i < m_NumLabels)
prev = labelAlpha->rlookup(i)[0];
m_Legal[i] = new int[m_NumLabels];
for (int j = 0; j < m_NumLabels; ++ j) {
char curr = labelAlpha->rlookup(j)[0];
m_Legal[i][j] = 0;
if ((prev == 'X' || prev == 'S' || prev == 'E')
&& (curr == 'S' || curr == 'B'))
m_Legal[i][j] = 1;
if ((prev == 'M' || prev == 'B') &&
(curr == 'M' || curr == 'E'))
m_Legal[i][j] = 1;
}
}
}
示例5: testConstructorDecompositionAlphabet
void ComposedElementTest::testConstructorDecompositionAlphabet() {
Alphabet cho;
cho.push_back(*hydrogen);
cho.push_back(*carbon);
cho.push_back(*oxygen);
std::vector<unsigned int> decomposition;
decomposition.push_back(static_cast<unsigned int>(3));
decomposition.push_back(static_cast<unsigned int>(2));
decomposition.push_back(static_cast<unsigned int>(1));
composed_element_type molecule(decomposition, cho);
CPPUNIT_ASSERT_EQUAL(molecule.getElementAbundance("C"),
static_cast<elements_container::mapped_type>(2));
CPPUNIT_ASSERT_EQUAL(molecule.getElementAbundance("H"),
static_cast<elements_container::mapped_type>(3));
CPPUNIT_ASSERT_EQUAL(molecule.getElementAbundance("O"),
static_cast<elements_container::mapped_type>(1));
// checks if isotope distribution is not yet initialized
CPPUNIT_ASSERT(molecule.getIsotopeDistribution().empty());
// checks if sequence is not yet initialized
CPPUNIT_ASSERT(molecule.getSequence().empty());
}
示例6: LzNode
void LZ78::encoding(Stream &stream, Alphabet &alpha, File &file) {
LzNode *curr = root;
char c;
// Para cada caractere de entrada
while(stream.hasNext()) {
c = stream.next();
// Se já existe um nó com o caractere c'
if(curr->child.count(c)) {
curr = curr->child[c];
// Não existe a substring procurada, então ..
} else {
// printf(" (%2d, %c)", curr->id, c);
serialize_int(file, curr->id);
serialize_int(file, alpha.getIndex(c));
// Criar um novo nó
LzNode *new_node = new LzNode(nextId++);
curr->child.insert(std::make_pair(c, new_node));
curr = root;
}
}
// Terminal
// printf(" (%2d, 0)\n", curr->id);
serialize_int(file, curr->id);
serialize_int(file, alpha.getIndex('\0'));
}
示例7: name
void Alphabets::LoadTxt(lem::Iridium::Macro_Parser &txt, Dictionary &dict)
{
lem::UCString name(txt.read().string());
if (Find(name) != UNKNOWN)
{
dict.GetIO().merr().printf(
"Alphabet [%us] is already declared\n"
, name.c_str()
);
throw E_ParserError();
}
const int id = storage->AddAlphabet(name);
Alphabet *a = new Alphabet(id, name);
a->LoadTxt(txt, dict);
storage->StoreAlphabet(*a);
name2id.insert(std::make_pair(name, id));
id2alphabet.insert(std::make_pair(id, a));
alphabets.push_back(a);
return;
}
示例8: TableTest_resolveNotClosed
bool TableTest_resolveNotClosed() {
// Table is not closed
Alphabet a;
a.addSymbol('0');
a.addSymbol('1');
// Figure 2
ObservationTable table1;
table1.addEntry("", "", true);
table1.addEntry("0", "", false);
table1.addEntry("1", "", false);
table1.addStringToS("");
table1.addStringToE("");
if (table1.getS().count("0") != 0) {
return false;
}
table1.resolveNotClosed(a);
if (table1.getS().count("0") != 1) {
return false;
}
return true;
}
示例9: if
void State::build_word(bool allowed, string* word, size_t len)
{
if (len == 0) {
return;
}
if (this->error_state) {
if (allowed) {
return;
}
}
if (this->get_end_state() && allowed) {
cout << "Accepting word: " << *word << endl;
} else if (!this->get_end_state() && !allowed) {
cout << "Rejecting word: " << *word << endl;
}
Alphabet* alpha = Alphabet::get_alphabet();
std::string* alpha_str = alpha->get_string();
for (size_t i = 0; i < alpha->get_size(); i++) {
string tmp_string = *word;
char c = (*alpha_str)[i];
tmp_string.push_back(c);
this->map_transitions[c]->build_word(allowed, &tmp_string,
len - 1);
}
}
示例10: testOperatorMinus
void ComposedElementTest::testOperatorMinus() {
// initializes alphabet
Alphabet cho;
cho.push_back(*hydrogen);
cho.push_back(*carbon);
cho.push_back(*oxygen);
composed_element_type molecule1("H10O6", cho), molecule2("O4H4", cho);
molecule1 -= molecule2;
CPPUNIT_ASSERT_EQUAL(molecule1.getElements().size(),
static_cast<elements_container::size_type>(2));
CPPUNIT_ASSERT_EQUAL(molecule1.getElementAbundance("O"),
static_cast<elements_container::mapped_type>(2));
CPPUNIT_ASSERT_EQUAL(molecule1.getElementAbundance("H"),
static_cast<elements_container::mapped_type>(6));
composed_element_type molecule3("O8H2", cho), molecule4("O6H7C5", cho);
molecule3 -= molecule4;
CPPUNIT_ASSERT_EQUAL(molecule3.getElements().size(),
static_cast<elements_container::size_type>(1));
CPPUNIT_ASSERT_EQUAL(molecule3.getElementAbundance("O"),
static_cast<elements_container::mapped_type>(2));
}
示例11: main
int main()
{
Alphabet *alphabet = new Alphabet();
vector<int> key;
key.push_back(2);
key.push_back(3);
key.push_back(1);
key.push_back(4);
isValidKey(key, alphabet->getLength());
string message = "breathjavaeatcpp";
cout << "message = [" << message << "]" << endl;
string encrypted = encrypt(key, alphabet, message);
cout << "encrypted = [" << encrypted << "]" << endl;
string decrypted = decrypt(key, alphabet, encrypted);
cout << "decrypted = [" << decrypted << "]" << endl;
delete alphabet;
return 0;
}
示例12: reset_error
void State::reset_error()
{
Alphabet* alpha = Alphabet::get_alphabet();
for (int idx = 0; idx < alpha->get_string()->size(); idx++) {
char c = alpha->get_string()->at(idx);
this->map_transitions[c] = this->get_error();
}
}
示例13: bignum_error
bool Base58::decode (const char* psz, Blob& vchRet, Alphabet const& alphabet)
{
CAutoBN_CTX pctx;
vchRet.clear ();
CBigNum bn58 = 58;
CBigNum bn = 0;
CBigNum bnChar;
while (isspace (*psz))
psz++;
// Convert big endian string to bignum
for (const char* p = psz; *p; p++)
{
// VFALCO TODO Make this use the inverse table!
// Or better yet ditch this and call raw_decode
//
const char* p1 = strchr (alphabet.chars(), *p);
if (p1 == nullptr)
{
while (isspace (*p))
p++;
if (*p != '\0')
return false;
break;
}
bnChar.setuint (p1 - alphabet.chars());
if (!BN_mul (&bn, &bn, &bn58, pctx))
throw bignum_error ("DecodeBase58 : BN_mul failed");
bn += bnChar;
}
// Get bignum as little endian data
Blob vchTmp = bn.getvch ();
// Trim off sign byte if present
if (vchTmp.size () >= 2 && vchTmp.end ()[-1] == 0 && vchTmp.end ()[-2] >= 0x80)
vchTmp.erase (vchTmp.end () - 1);
// Restore leading zeros
int nLeadingZeros = 0;
for (const char* p = psz; *p == alphabet.chars()[0]; p++)
nLeadingZeros++;
vchRet.assign (nLeadingZeros + vchTmp.size (), 0);
// Convert little endian data to big endian
std::reverse_copy (vchTmp.begin (), vchTmp.end (), vchRet.end () - vchTmp.size ());
return true;
}
示例14: MayaNumber
MayaNumber(const Alphabet& alphabet, const string& lines)
: alphabet_(alphabet)
{
size_t n = alphabet.height() * alphabet.width();
for (int i = 0; i < lines.length(); i += n)
{
symbols_.push_back(alphabet.fromValue(lines.substr(i, n)));
}
}
示例15: TableTest_resolveNotConsistent
bool TableTest_resolveNotConsistent() {
// Table is not consistent
Alphabet a;
a.addSymbol('0');
a.addSymbol('1');
// Figure 8
ObservationTable table1;
table1.addStringToS("");
table1.addStringToS("0");
table1.addStringToS("1");
table1.addStringToS("11");
table1.addStringToS("01");
table1.addStringToS("011");
table1.addStringToE("");
table1.addStringToE("0");
table1.addEntry("", "", true);
table1.addEntry("", "0", false);
table1.addEntry("0", "", false);
table1.addEntry("0", "0", true);
table1.addEntry("1", "", false);
table1.addEntry("1", "0", false);
table1.addEntry("11", "", true);
table1.addEntry("11", "0", false);
table1.addEntry("01", "", false);
table1.addEntry("01", "0", false);
table1.addEntry("011", "", false);
table1.addEntry("011", "0", true);
table1.addEntry("00", "", true);
table1.addEntry("00", "0", false);
table1.addEntry("10", "", false);
table1.addEntry("10", "0", false);
table1.addEntry("110", "", false);
table1.addEntry("110", "0", true);
table1.addEntry("111", "", false);
table1.addEntry("111", "0", false);
table1.addEntry("010", "", false);
table1.addEntry("010", "0", false);
table1.addEntry("0110", "", true);
table1.addEntry("0110", "0", false);
table1.addEntry("0111", "", false);
table1.addEntry("0111", "0", false);
if (table1.getE().count("1") != 0) {
return false;
}
table1.resolveNotConsistent(a);
if (table1.getE().count("1") != 1) {
return false;
}
return true;
}