String Algorithms in C: Efficient Text Representation and Search 1st Edition Thomas Mailund download
String Algorithms in C: Efficient Text Representation and Search 1st Edition Thomas Mailund download
https://textbookfull.com/product/string-algorithms-in-c-
efficient-text-representation-and-search-1st-edition-thomas-
mailund/
https://textbookfull.com/product/the-joys-of-hashing-hash-table-
programming-with-c-1st-edition-thomas-mailund/
https://textbookfull.com/product/pointers-in-c-programming-a-
modern-approach-to-memory-management-recursive-data-structures-
strings-and-arrays-thomas-mailund/
https://textbookfull.com/product/domain-specific-languages-in-r-
advanced-statistical-programming-1st-edition-thomas-mailund/
https://textbookfull.com/product/domain-specific-languages-in-r-
advanced-statistical-programming-1st-edition-thomas-mailund-2/
C Data Structures and Algorithms Explore the
possibilities of C for developing a variety of
efficient applications Marcin Jamro
https://textbookfull.com/product/c-data-structures-and-
algorithms-explore-the-possibilities-of-c-for-developing-a-
variety-of-efficient-applications-marcin-jamro/
https://textbookfull.com/product/functional-data-structures-in-r-
advanced-statistical-programming-in-r-thomas-mailund/
https://textbookfull.com/product/metaprogramming-in-r-advanced-
statistical-programming-for-data-science-analysis-and-
finance-1st-edition-thomas-mailund/
https://textbookfull.com/product/c-data-structures-and-
algorithms-harness-the-power-of-c-to-build-a-diverse-range-of-
efficient-applications-2nd-edition-marcin-jamro/
https://textbookfull.com/product/introducing-markdown-and-pandoc-
using-markup-language-and-document-converter-1st-edition-thomas-
mailund/
String
Algorithms in C
Ef f icient Text Representation and Search
—
Thomas Mailund
WOW! eBook
www.wowebook.org
String Algorithms in C
Efficient Text Representation
and Search
Thomas Mailund
WOW! eBook
www.wowebook.org
String Algorithms in C: Efficient Text Representation and Search
Thomas Mailund
Aarhus N, Denmark
WOW! eBook
www.wowebook.org
Table of Contents
About the Author���������������������������������������������������������������������������������������������������� vii
Chapter 1: Introduction�������������������������������������������������������������������������������������������� 1
Notation and conventions������������������������������������������������������������������������������������������������������������� 1
Graphical notation������������������������������������������������������������������������������������������������������������������������� 2
Code conventions�������������������������������������������������������������������������������������������������������������������������� 3
Reporting a sequence of results��������������������������������������������������������������������������������������������������� 5
iii
WOW! eBook
www.wowebook.org
Table of Contents
iv
WOW! eBook
www.wowebook.org
Table of Contents
Index��������������������������������������������������������������������������������������������������������������������� 287
WOW! eBook
www.wowebook.org
About the Author
Thomas Mailund is an associate professor in bioinformatics at Aarhus University,
Denmark. He has a background in math and computer science. For the past decade,
his main focus has been on genetics and evolutionary studies, particularly comparative
genomics, speciation, and gene flow between emerging species. He has published R
Data Science Quick Reference, The Joys of Hashing, Domain-Specific Languages in R,
Beginning Data Science in R, Functional Programming in R, and Metaprogramming in R,
all from Apress, as well as other books.
vii
WOW! eBook
www.wowebook.org
About the Technical Reviewer
Jason Whitehorn is an experienced entrepreneur and
software developer and has helped many companies
automate and enhance their business solutions through data
synchronization, SaaS architecture, and machine learning.
Jason obtained his Bachelor of Science in Computer Science
from Arkansas State University, but he traces his passion
for development back many years before then, having first
taught himself to program BASIC on his family’s computer
while still in middle school.
When he’s not mentoring and helping his team at work,
writing, or pursuing one of his many side projects, Jason enjoys spending time with his
wife and four children and living in the Tulsa, Oklahoma region. More information about
Jason can be found on his website: https://jason.whitehorn.us.
ix
WOW! eBook
www.wowebook.org
CHAPTER 1
Introduction
Algorithms operating on strings are fundamental to many computer programs, and in
particular searching for one string in another is the core of many algorithms. An example
is searching for a word in a text document, where we want to know everywhere it occurs.
This search can be exact, meaning that we are looking for the positions where the word
occurs verbatim, or approximative, where we allow for some spelling mistakes.
This book will teach you fundamental algorithms and data structures for exact and
approximative search. The goal of the book is not to cover the theory behind the material
in great detail. However, we will see theoretical considerations where relevant. The
purpose of the book is to give you examples of how the algorithms can be implemented.
For every algorithm and data structure in the book, I will present working C code and
nowhere will I use pseudocode. When I argue for the correctness and running time of
algorithms, I do so intentionally informal. I aim at giving you an idea about why the
algorithms solve a specific problem in a given time, but I will not mathematically prove so.
You can copy all the algorithms and data structures in this book from the pages,
but they are also available in a library on GitHub: https://github.com/mailund/
stralg. You can download and link against the library or copy snippets of code into
your own projects. On GitHub you can also find all the programs I have used for time
measurement experiments so you can compare the algorithm’s performance on your
own machine and in your own runtime environment.
N
otation and conventions
Unless otherwise stated, we use x, y, and p to refer to strings and i, j, k, l, and h to denote
indices. We use 𝜖 to denote the empty string. We use a, b, and c for single characters. As
in C, we do not distinguish between strings and pointers to a sequence of characters.
Since the book is about algorithms in C, the notation we use matches that which is
used for strings, pointers, and arrays in C. Arrays and strings are indexed from zero,
1
© Thomas Mailund 2020
T. Mailund, String Algorithms in C, https://doi.org/10.1007/978-1-4842-5920-7_1
WOW! eBook
www.wowebook.org
Chapter 1 Introduction
that is, A[0] is the first value in array A (and x[0] is the first character in string x). The ith
character in a string is at index i − 1.
When we refer to a substring, we define it using two indices, i and j, i ≤ j, and we
write x[i, j] for the substring. The first index is included and the second is not, that is,
x[i, j] = x[i]x[i + 1] · · · x[ j − 1]. If a string has length n, then the substring x[0, n] is the full
string. If we have a character a and a string x, then ax denotes the string that has a as its
first character and is then followed by the string x. We use ak to denote a sequence of as
of length k. The string a3 x has a as its first three characters and is then followed by x.
A substring that starts at index 0, x[0, i], is a prefix of the string, and it is a proper prefix
if it is neither the empty string x[0, 0] = 𝜖 nor the full string x[0, n]. A substring that ends
in n, x[i, n], is a suffix, and it is a proper suffix if it is neither the empty string nor the full
string. We will sometimes use x[i, ] for this suffix.
We use $ to denote a sentinel in a string, that is, it is a character that is not found in
the rest of the string. It is typically placed at the end of the string. The zero-terminated
C strings have the zero byte as their termination sentinel, and unless otherwise stated,
$ refers to that. All C strings x have a zero sentinel at index n if the string has length n,
x = x[0]x[1] · · · x[n − 1]0. For some algorithms, the sentinel is essential; in others, it is not.
We will leave it out of the notation when a sentinel isn’t needed for an algorithm, but
naturally include the sentinel when it is necessary.
G
raphical notation
Most data structures and algorithmic ideas are simpler to grasp if we use drawings to
capture the structure of strings rather than textual notation. Because of this, I have chosen to
provide more figures in this book than you will typically see in a book on algorithms. I hope
you will appreciate it. If there is anything you find unclear about an algorithm, I suggest you
try to draw key strings yourself and work out the properties you have problems with.
In figures, we represent strings as rectangles. We show indices into a string as arrows
pointing to the index in the string; see Figure 1-1. In this notation, we do not distinguish
between pointers and indices. If a variable is an index j and it points into x, then what
it points to is x[ j], naturally. If the variable is a pointer, y, then what it points to is ∗y.
Whether we are working with pointers or indices should be clear from the context. It will
undoubtedly be clear from the C implementations. We represent substrings by boxes of
a different color inside the original string-rectangle. If we specify the indices defining the
substring, we include their start and stop index (where the stop index points one after
the end of the substring).
2
WOW! eBook
www.wowebook.org
Chapter 1 Introduction
Figure 1-2. Graphical notation for comparing indices in two different strings
C
ode conventions
There is a trade-off between long variables and type names and then the line within a
book. In many cases, I have had to use an indentation that you might not be used to. In
function prototypes and function definitions, I will generally write with one variable per
line, indented under the function return type and name, for example:
void compute_z_array(
const unsigned char *x,
uint32_t n,
uint32_t *Z
);
3
WOW! eBook
www.wowebook.org
Chapter 1 Introduction
void compute_reverse_z_array(
const unsigned char *x,
uint32_t m,
uint32_t *Z
);
I make an exception for functions that take no arguments, that is, have void as their
argument type.
There are many places where an algorithm needs to use characters to look up in
arrays. If you use the conventional C string type, char *, then the character can be either
signed or unsigned, depending on your compiler, and you have to cast the type to avoid
warnings. A couple of places we also have to make assumptions about the alphabet
size. Because of this, I use arrays of uint8_t with a zero termination sentinel as strings.
On practically all platforms, char is 8 bits so this type is, for all intents and purposes, C
strings. We are just guaranteed that we can use it unsigned and that the alphabet size
WOW! eBook
www.wowebook.org
Chapter 1 Introduction
void bmh_search(
const uint8_t *x,
const uint8_t *p
) {
uint32_t n = strlen((char *)x);
uint32_t m = strlen((char *)p);
// Preprocessing
int jump_table[256];
WOW! eBook
www.wowebook.org
Chapter 1 Introduction
// Searching
for (uint32_t j = 0;
j < n - m + 1;
j += jump_table[x[j + m - 1]]) {
int i = m - 1;
while (i > 0 && p[i] == x[j + i])
--i;
if (i == 0 && p[0] == x[j]) {
REPORT(j);
}
}
}
If a global report function is all you need in your program, then this is an excellent
solution. Often, however, we need different reporting functions for separate calls to the
search function. Or we need the report function to collect data for further processing
(and preferably not use global variables). We need some handle to choose different
report functions and to provide them with data.
One approach is using callbacks: Provide a report function and data argument to the
search function and call the report function with the data when we find an occurrence.
In the following implementation, I am assuming we have defined the function type for
reporting, report_function, and the type for data we can add to it, report_function_
data, somewhere outside of the search function.
void bmh_search_callback(
const uint8_t *x,
const uint8_t *p,
report_function report,
report_function_data data
) {
uint32_t n = strlen((char *)x);
uint32_t = strlen((char *)p);
// Preprocessing
uint32_t jump_table[256];
WOW! eBook
www.wowebook.org
Chapter 1 Introduction
// Searching
for (uint32_t j = 0;
j < n - m + 1;
j += jump_table[x[j + m - 1]]) {
int i = m - 1;
while (i > 0 && p[i] == x[j + i])
--i;
if (i == 0 && p[0] == x[j]) {
report(j, data);
}
}
}
WOW! eBook
www.wowebook.org
Chapter 1 Introduction
The iterator structure contains the loop information. That means it must save the
preprocessing data from when we create it and information about how to resume the
loop after each time it is suspended. To report occurrences, it takes a “match” structure
through which it can inform the caller about where matches occur. The iterator is
initialized with data that determines what it should loop over. The loop is handled
using a “next” function that returns true if there is another match (and if it does it will
have filled out match). If there are no more matches, and the loop terminates, then it
returns false. The iterator might contain allocated resources, so there should always be a
function for freeing those.
In an iterator for the BMH, we would keep the string, pattern, and table we build in
the preprocessing.
struct bmh_match_iter {
const uint8_t *x; uint32_t n;
const uint8_t *p; uint32_t m;
int jump_table[256];
uint32_t j;
};
struct match {
uint32_t pos;
};
void init_bmh_match_iter(
struct bmh_match_iter *iter,
const uint8_t *x, uint32_t n,
const uint8_t *p, uint32_t m
) {
// Preprocessing
iter->j = 0;
iter->x = x; iter->n = n;
iter->p = p; iter->m = m;
8
WOW! eBook
www.wowebook.org
Chapter 1 Introduction
bool next_bmh_match(
struct bmh_match_iter *iter,
struct match *match
) {
const uint8_t *x = iter->x;
const uint8_t *p = iter->p;
uint32_t n = iter->n;
uint32_t m = iter->m;
int *jump_table = iter->jump_table;
// Searching
for (uint32_t j = iter->j;
j < n - m + 1;
j += jump_table[x[j + m - 1]]) {
int i = m - 1;
while (i > 0 && p[i] == x[j + i]) {
i--;
}
if (i == 0 && p[0] == x[j]) {
match->pos = j;
iter->j = j +
jump_table[x[j + m - 1]];
return true;
}
}
return false;
}
9
WOW! eBook
www.wowebook.org
Chapter 1 Introduction
We set up the loop with information from the iterator and search from there. If we
find an occurrence, we store the new loop information in the iterator and the match
information in the match structure and return true. If we reach the end of the loop, we
report false.
We have not allocated any resources when we initialized the iterator, so we do not
need to free anything.
void dealloc_bmh_match_iter(
struct bmh_match_iter *iter
) {
// Nothing to do here
}
Since the deallocation function doesn’t do anything, we could leave it out. Still,
consistency in the use of iterators helps avoid problems. Plus, should we at some point
add resources to the iterator, then it is easier to update one function than change all the
places in the code that should now call a deallocation function.
Iterators complicate the implementation of algorithms, especially if they are
recursive and the iterator needs to keep track of a stack. Still, they greatly simplify the
user interface to your algorithms, which makes it worthwhile to spend a little extra time
implementing them. In this book, I will use iterators throughout.
10
WOW! eBook
www.wowebook.org
CHAPTER 2
Classical algorithms
for exact search
We kick the book off by looking at classical algorithms for exact search, that is, finding
positions in a string where a pattern string matches precisely. This problem is so
fundamental that it received much attention in the very early days of computing, and by
now, there are tens if not hundreds of approaches. In this chapter, we see a few classics.
Recall that we use iterators whenever we have an algorithm that loops over results
that should be reported. All iterators must be initialized, and the resources they hold must
be deallocated when we no longer need the iterator. When we loop, we have a function
that returns true when there is something to report and false when the loop is done. The
values the iterator reports are put in a structure that we pass along to the function that
iterates to the next value to report. For the algorithms in this chapter, we initialize the
iterators with the string in which we search, the pattern we search for, and the lengths of
the two strings. Iterating over all occurrences of the pattern follows this structure:
When we report an occurrence, we get the position of the match, so the structure the
iterator use for reporting is this:
struct match {
uint32_t pos;
};
11
© Thomas Mailund 2020
T. Mailund, String Algorithms in C, https://doi.org/10.1007/978-1-4842-5920-7_2
WOW! eBook
www.wowebook.org
Chapter 2 Classical algorithms for exact search
N
aïve algorithm
The simplest way imaginable for exact search is to iteratively move through the string
x, with an index j that conceptually runs the pattern p along x, and at each index start
matching the pattern against the string using another index, i (see Figure 2-1). The
algorithm has two loops, one that iterates j through x and one that iterates i through
p, matching x[i + j] against p[i] along the way. We run the inner loop until we see a
mismatch or until we reach the end of the pattern. In the former case, we move p one
step forward and try matching again. In the second case, we report an occurrence at
position j and then increment the index so we can start matching at the next position. We
stop the outer loop when index j is greater than n − m. If it is, there isn’t room for a match
that doesn’t run past the end of x.
We terminate the comparison of x[i + j] and p[i] when we see a mismatch, so in the best
case, where the first character in p never matches a character in x, the algorithm runs in
time O(n) where n is the length of x. In the worst case, we match all the way to the end of p
at each position, and in that case, the running time is O(nm) where m is the length of p.
To implement the algorithm using an iterator, the iterator needs to remember
the string to search in and the pattern to search for—so we do not need to pass these
along each time we increment the iterator with potentials for errors if we use the wrong
strings—and we keep track of how far into the string we have searched.
struct naive_match_iter {
const uint8_t *x; uint32_t n;
const uint8_t *p; uint32_t m;
uint32_t current_index;
};
12
WOW! eBook
www.wowebook.org
Chapter 2 Classical algorithms for exact search
When we initialize the iterator, we remember the two strings and set the current
index to zero—before we start iterating we are at the beginning of the string.
void init_naive_match_iter(
struct naive_match_iter *iter,
const uint8_t *x, uint32_t n,
const uint8_t *p, uint32_t m
) {
iter->x = x; iter->n = n;
iter->p = p; iter->m = m;
iter->current_index = 0;
iter->current_index = 0;
}
When we increment the iterator, we follow the algorithm as described earlier except
that we start the outer loop at the index saved in the iterator. We search from this index in
an outer loop, and at each new index, we try to match the pattern with an inner loop. We
break the inner loop if we see a mismatching character, and if the inner loop reaches the
end, we have a match and report it. Before we return, we set the iterator index and store
the matching position in the match structure.
bool next_naive_match(
struct naive_match_iter *iter,
struct match *match
) {
uint32_t n = iter->n, m = iter->m;
const uint8_t *x = iter->x;
const uint8_t *p = iter->p;
13
WOW! eBook
www.wowebook.org
Chapter 2 Classical algorithms for exact search
if (i == m) {
iter->current_index = j + 1;
match->pos = j;
return true;
}
}
return false;
}
The code
makes sure that it is possible to match the pattern at all and that the pattern isn’t
empty. This is something we could also test when we initialize the iterator. However, we
do not have a way of reporting that we do not have a possible match there, so we put the
test in the “next” function.
We do not allocate any resources when we initialize the iterator, so we do not need to
do anything when deallocating it either. We still need the deallocator function, however,
so we always use the same design pattern when we use iterators. To make sure that if we,
at some point in the future, need to free something that we put in an iterator, then all
users of the iterator (should) have added code for this.
void dealloc_naive_match_iter(
struct naive_match_iter *iter
) {
// Nothing to do here...
}
14
WOW! eBook
www.wowebook.org
Chapter 2 Classical algorithms for exact search
We can make the following observation about borders and border arrays: The longest
border of x[0, i] is either the empty string or an extension of a border of x[0, i − 1]. If the
letter at x[i] is a, the border of x[0, i] is some string y followed by a. The y string must be
both at the beginning and end of x[0, i − 1] (see Figure 2-3), so it is a border of x[0, i − 1].
The longest border for x[0, i] is the longest border of x[0, i − 1] that is followed by a (which
may be the empty border if the string x begins with a) or the empty border if there is no
border we can extend with a.
Another observation is that if you have two borders to a string, then the shorter of the
two is a border of the longer; see Figure 2-4.
15
WOW! eBook
www.wowebook.org
Chapter 2 Classical algorithms for exact search
16
WOW! eBook
www.wowebook.org
Chapter 2 Classical algorithms for exact search
Figure 2-5. Searching for the longest border we can extend with letter a
An implementation of the border array construction algorithm can look like this:
ba[0] = 0;
for (uint32_t i = 1; i < m; ++i) {
uint32_t b = ba[i - 1];
while (b > 0 && x[i] != x[b])
b = ba[b - 1];
ba[i] = (x[i] == x[b]) ? b + 1 : 0;
}
17
WOW! eBook
www.wowebook.org
Chapter 2 Classical algorithms for exact search
An iterator that searches a string with this algorithm must contain the border
array of p, the index into x we have reached, and the b variable from the border array
construction algorithm.
struct border_match_iter {
const uint8_t *x; uint32_t n;
const uint8_t *p; uint32_t m;
uint32_t *border_array;
uint32_t i; uint32_t b;
};
18
WOW! eBook
www.wowebook.org
Chapter 2 Classical algorithms for exact search
When we initialize the iterator, we set its index to zero. That, after all, is where we
start searching in x. We also set the iterator’s b variable to zero. We imagine that we start
the search after a sentinel, so the longest border at the start index for x has length zero.
We then allocate and compute the border array.
void init_border_match_iter(
struct border_match_iter *iter,
const uint8_t *x, uint32_t n,
const uint8_t *p, uint32_t m
) {
iter->x = x; iter->n = n;
iter->p = p; iter->m = m;
iter->i = iter->b = 0;
Since we allocated the border array when we initialized the iterator, we need to free it
again when we deallocate it.
void dealloc_border_match_iter(
struct border_match_iter *iter
) {
free(iter->border_array);
}
19
WOW! eBook
www.wowebook.org
Chapter 2 Classical algorithms for exact search
bool next_border_match(
struct border_match_iter *iter,
struct match *match
) {
const uint8_t *x = iter->x;
const uint8_t *p = iter->p;
uint32_t *ba = iter->border_array;
uint32_t b = iter->b;
uint32_t m = iter->m;
uint32_t n = iter->n;
return false;
}
20
WOW! eBook
www.wowebook.org
Chapter 2 Classical algorithms for exact search
K
nuth-Morris-Pratt
The Knuth-Morris-Pratt (KMP) algorithm also uses borders to achieve a best- and worst-
case running time of O(n + m), but it uses the borders in a slightly different way. Before
we get to the algorithm, however, I want to convince you that we can, conceptually, move
the pattern p through x in two different ways; see Figure 2-7. We can let j be an index
into x and imagine p starting there. When we test if p matches there, we use a pointer
into p, i, and test x[ j + i] against p[i] for increasing i. To move p to another position in x,
we change j, for example, to slide p one position to the right we increment j by one.
Alternatively, we can imagine p aligned at position j − i for some index j in x and an
index i into p. If we change i, we move j − i so we move p. If, for example, we want
to move p one step to the right, we can decrement i by one. To understand how the
KMP algorithm works, it is useful to think about moving p in the second way. We will
increment the j and i indices when matching characters, but when we get a mismatch,
we move p by decrementing i.
The idea in KMP is to move p along x as we would in the naïve algorithm, but move
a little faster when we have a mismatch. We use index j to point into x and i to point
into p. We match x[ j] against p[i] as we scan along x and the pattern is aligned against
x at index j − i. We can move p’s position by modifying either i or j. Consider a place
in the algorithm where we have matched p[0, i] against x[ j − i, j] and see a mismatch.
In the naïve algorithm, we would move p one step to the right and start matching p
again at that position. We would set i to zero to start matching from the beginning of p,
and we would decrement j to j − i + 1 to match at the new position at which we would
match p. With KMP we will skip positions where we know that p cannot match, and we
use borders to do this.
21
WOW! eBook
www.wowebook.org
Another Random Scribd Document
with Unrelated Content
C’est singulier comme l’habitude nous rend indifférents pour les
choses les plus révoltantes, à un tel degré que nous ne les voyons pas,
quoique tous les jours elles se passent sous nos yeux.
Ainsi, une petite bourgeoise qui a de l’ordre et qui tient bien sa maison,
quelque jolie, mignonne et dégoûtée qu’elle puisse être,—envoie le matin
sa cuisinière à une de ces morgues où les bouchers étendent des cadavres
d’animaux—sans que cela attriste ni dégoûte les passants.
Puis, vers six heures, on se met à table,—et la maîtresse du logis,—
bourgeoise—ou non,—supposez-la, si vous voulez, la plus élégante et la
plus belle,—la plus éthérée et la plus diaphane,—dissèque et fouille
successivement divers cadavres, s’efforçant de se rappeler de quel morceau
du corps mort aime à se repaître tel ou tel convive.
Celui-ci veut que le cadavre soit encore saignant;
Cet autre le préfère un peu plus cuit;
Elle engage son voisin à manger l’œil du veau,—ou telle autre partie du
cadavre qui passe pour plus délicate et plus recherchée.
Voici un homme qui n’a plus faim;—mais il mange encore.—C’est si
amusant de faire tenir dans son estomac le plus de cadavre possible!—
D’ailleurs, quelques-uns se font gloire d’être gros mangeurs,—et c’est leur
position dans le monde.
Et puis, on a mêlé à tous ces corps morts des ingrédients qui en hâtent la
décomposition dans l’estomac et permettent d’en entasser davantage.—
Entre les animaux qui mange de la chair,—l’homme est le seul qui en
mange pour son plaisir, c’est-à-dire au delà de sa faim.
De telle sorte qu’il m’est arrivé plus d’une fois—de voir à mes yeux se
métamorphoser tout à coup la femme la plus gracieuse, donnant à dîner,—
en une goule partageant un cadavre à une volée de corbeaux affamés.
Il est vrai qu’on a ajouté à tout cela l’usage dégoûtant de se rincer la
bouche à table,—sordide propreté dont, pour ma part, j’ai soin de
m’abstenir.
A propos de dîner, il faut encore remarquer que beaucoup de gens,
en invitant, songent beaucoup moins à être agréables aux gens qu’ils
reçoivent qu’à les écraser par l’opulence de leur maison,—beaucoup plus à
les étonner qu’à les nourrir.—C’est dans ces maisons surtout qu’on mange
des primeurs,—c’est-à-dire des légumes qui ont besoin d’être étiquetés pour
qu’on ne les prenne pas au goût pour une seule et même herbe sans saveur.
Beaucoup de personnes, en vous donnant des pois verts à certaines époques,
n’ont évidemment d’autre intention que de vous montrer des pois chers.
J’ai déjà, à plusieurs reprises, donné à M. le comte de Montalivet la
preuve d’estime de lui dénoncer à lui-même les abus qui se commettent
dans son administration.
Je viens aujourd’hui lui apprendre qu’on fait du roi de France un
jardinier et un fruitier,—et que les autres jardiniers et les autres fruitiers, ses
confrères, se plaignent amèrement de lui.
Il y a à Versailles,—au château,—un potager fort beau et fort bien cultivé
par le jardinier Grison. Ce potager produit beaucoup au delà de la
consommation du château, surtout en fruits et en légumes de primeurs;—
vous croyez peut-être que le surplus est consacré à des présents.
Nullement,—on le vend à beaux deniers comptants à divers fruitiers de
Paris.
Et, comme ceux qui vendent les produits de Versailles les ont pour rien,
ils les donnent aux marchands à un prix auquel les producteurs industriels
ne peuvent abaisser les leurs.
Pour vous montrer que je suis bien instruit, nous allons procéder par
exemples.
EXEMPLE:—Il n’y a qu’un seul jardinier qui fasse des haricots verts de
primeur,—c’est un nommé Gauthier qui demeure au Petit-Montrouge.
Cette année, au 20 février, on n’avait encore vendu que deux fois des
haricots verts à Paris.
Les premiers par le roi,—les seconds par M. de Rothschild, qui a un
jardin à Boulogne,—à Maillez, fruitier, marché Saint-Honoré.
Aujourd’hui Gauthier, qui, avec moins de ressources que ses deux
rivaux, arrive cependant presque en même temps qu’eux,—est obligé, pour
rentrer dans ses frais, de vendre ses haricots vingt ou vingt-quatre francs la
livre,—tandis que ses concurrents, le roi de France et M. de Rothschild, les
donnent à meilleur marché.
L’année dernière,—Gauthier, plutôt que de donner ses haricots à vil prix,
a mieux aimé en faire des présents.
C’est agir royalement.
AUTRE EXEMPLE:—L’an dernier, à Trianon, pour un dîner qui devait avoir
lieu, on avait demandé trente ananas au potager de Versailles;—le dîner
n’eut pas lieu, et le lendemain les ananas étaient vendus à Bailli, glacier, rue
Neuve-des-Petits-Champs,—à un prix auquel ne peuvent les céder les
producteurs, auxquels chaque ananas coûte de huit à quinze francs.
Autrefois, les cultivateurs de Versailles obtenaient la permission de faire
prendre dans la forêt de la terre de bruyère, nécessaire à leur travail, qui y
est fort bonne;—mais la liste civile a pris le parti de la réserver pour le
potager de Versailles et pour les pépinières de Trianon,—tandis que les
jardiniers marchands sont obligés de la tirer de Palaiseau et de Saint-Léger,
c’est-à-dire de quatre à cinq lieues de là.
Les jardiniers ont un si grand besoin de feuilles d’arbres ramassées et de
mousse, qu’ils les payent, l’hiver, huit ou neuf francs par voiture. Il y a
quelques années, les pépiniéristes ont fait une pétition pour demander la
réforme de quelques abus, et on leur a supprimé la permission de ramasser
des feuilles,—permission qui, du reste, leur a été rendue depuis.
Je sais bien,—monsieur le comte,—qu’Abdalonyme était jardinier avant
d’être roi,—et que Dioclétien le fut après avoir été maître du monde;
Mais je ne vois aucun prince qui ait cumulé ces deux professions de roi
et de maraîcher, et qui les ait exercées simultanément.
J’en excepterais un duc de Pirmasentz, ville de soixante-dix-huit
maisons, dont j’ai raconté l’histoire dans un livre appelé Einerley, et qui
cultivait des œillets,—mais celui-là ne les vendait pas.
Croyez-vous, monsieur le comte, qu’il soit bien utile à la gloire du roi
Louis-Philippe qu’il soit le premier à donner ce spectacle?
Voici ce que me rapporte une guêpe, qui a passé les barrières et qui est
allée du côté de Versailles pour voir si le printemps s’avance.
On lit dans un journal, sous la rubrique de Calais: «L’éclipse de
lune a été la cause bien involontaire de l’échouement d’un de nos bateaux
pêcheurs.»
Voici des choses un peu fortes que me dit une guêpe nouvellement
enrôlée dans mes escadrons.—Si quelqu’un avait des preuves à me donner
contre les assertions de ma nouvelle recrue,—je les accepterais et les
enregistrerais avec plaisir,—ainsi que je le fais et le ferai toujours chaque
fois qu’on me démontre ou me démontrera que j’ai été ou que j’aurai été
mal informé.
Le maréchal Soult nous a appris entre autres choses, dans la séance du
22 janvier, qu’il avait gagné la bataille de Marengo tout en défendant
Gênes.
Cette victoire, si opiniâtrément disputée par les Autrichiens au premier
consul Bonaparte, ne lui est pas moins vivement contestée par les Français.
Du vivant de l’Empereur, certaines gens prétendaient que c’était le
général Desaix qui avait gagné la bataille. Le fait est qu’il y fut tué.
Sous la Restauration, feu le duc de Valmy passait pour avoir gagné la
bataille par une certaine charge de cavalerie.
Voici maintenant M. le maréchal Soult qui nous apprend qu’à lui seul est
dû l’honneur de cette victoire, de même que celle d’Austerlitz.
Il y a trois ans, M. le maréchal Clauzel, dans ses Explications, apprit à
toute la France qu’il avait gouverné Raguse et couvert de belles routes toute
la côte dalmate. Il se vantait, en outre, d’avoir amené son corps d’armée à
l’Empereur sur le champ de bataille de Wagram.
Vérification faite, il se trouva que tout ce que ledit maréchal Clauzel
croyait avoir fait appartenait en propre au maréchal Marmont, duc de
Raguse, sous les ordres duquel M. Clauzel était alors employé.
Pendant quinze ans le maréchal Macdonald s’est laissé appeler par tous
les journaux vainqueur de Raab.
Cette bourde a été reproduite dernièrement par M. Ph. de Ségur dans un
éloge qu’il a prononcé en Chambre des pairs.
Le fait est que la bataille de Raab a été gagnée par le prince Eugène
Beauharnais, qui commandait l’armée d’Italie; à la vérité, le maréchal
Macdonald, alors général de division, servait sous les ordres de ce prince,
mais il n’assista même pas à cette bataille, étant avec sa division à une
journée en arrière.
Toutes ces choses pourraient bien devenir de l’histoire si la critique
contemporaine n’y met bon ordre. Celui de nos maréchaux qui vivra le plus
longtemps finirait par avoir gagné, à lui tout seul, toutes les batailles de la
Révolution et de l’Empire.
Nous avons déjà parlé des avantages incontestables que procurent
au pays les fréquents changements de ministère dont nous jouissons depuis
quelques années. A peine les administrations et les institutions ont-elles
commencé à recevoir une impulsion dans une ligne quelconque,—qu’un
autre ministère vient changer la direction pour une autre, qui sera encore
changée avant qu’on ait atteint aucun but.
Il y a encore d’autres agréments attachés à ce système, agréments qu’il
n’est peut-être pas mauvais de dévoiler. Les ministres sortants—
ressemblent à ces marins—dans une scène fort bien décrite par M. Sue,—
qui, après dîner, s’amusent à jeter, par les fenêtres, la vaisselle et les
meubles. On pourrait encore les comparer à ces marchandes de salade de la
halle, qui, chassées à une certaine heure par les sergents de ville,—offrent, à
un vil prix, le reste de leur marchandise.
Au moment du départ, toutes les complaisances, toutes les amitiés, tous
les dévouements, sont admis à une grande curée de tout ce qui reste à la
disposition des ministres: les croix, les emplois, l’argent, sont distribués à la
manière des comestibles aux anciennes fêtes publiques.—Pendant que le
ministre s’en va,—on l’arrête sur l’escalier, dans la cour,—à la porte du
ministère,—il est encore un peu ministre: on lui fait signer, signer, signer.
Tout cela se fait avec tant de confusion, qu’il est arrivé quelquefois, par
hasard, et sans mauvaise intention, que l’on ait commis quelque mesure
utile, que l’on se soit laissé aller à décerner une récompense méritée. Le
plus sûr est pourtant de ne pas s’y fier.
Il est un reproche qu’on me fait fréquemment.—Je reçois une lettre ce
matin qui est la soixantième, contenant à peu près les mêmes choses; je
réponds aux soixante lettres et aux soixante reproches à la fois: Pourquoi
n’avez-vous pas de couleur?
Il faut que j’explique ce qu’on appelle,—en journalisme,—avoir une
couleur. Quand vous voulez avoir une couleur,—je vous fais grâce des
nuances,—vous annoncez que vous êtes pour ou contre le pouvoir.
Si vous êtes pour le pouvoir, de ce moment vous êtes enchanté de tout ce
qu’il fait et de tout ce qu’il fera; s’il pleut, vous en rendez grâce à sa haute
sagacité, à sa paternelle prudence. Si le pouvoir dit: «Comment vous portez-
vous?» vous citez le mot charmant; les cheveux de M. Bugeaud vous
paraissent blond cendré; M. Fulchiron est un poëte distingué. Le pouvoir
ferait guillotiner la moitié de la nation, brûler les moissons, rôtir les enfants,
que vous n’en feriez pas moins l’éloge de son inépuisable bonté.—Si vous
êtes dans l’opposition, tout ministre est un voleur, un traître. Le roi ne peut
se promener dans son jardin sans que vous vous croyiez obligé de crier à la
tyrannie et à l’arbitraire. A tout homme qui éprouve des contrariétés de la
part de la police vous êtes obligé de tresser des couronnes. Le
gouvernement répandrait l’abondance, la paix, l’union, dans toute la France,
que ce n’en serait pas moins pour vous un gouvernement absurde, ennemi
du pays, et qui pèserait sur la France.
Ne pas avoir de couleur, c’est ne suivre de règle que le sens
commun, c’est blâmer le mal, louer le bien, rire du ridicule, quel qu’en soit
l’auteur; c’est garder entre tous les partis du bon sens, de la bonne foi, du
jugement et de l’esprit.
Grande nouvelle: les journaux nous annoncent que nous avons enfin
un poëme épique, la divine épopée.—Il paraît que c’est une chose fort
agréable et fort utile que d’avoir un poëme épique,—car dans tous les temps
on a agité cette question: «Avons-nous un poëme épique?» Tous les vingt
ans—il en paraît un nouveau,—et on dit alors: «La France n’avait pas de
poëme épique.»
Si un poëme épique se compose de quelques milliers de vers très-
ennuyeux, nous avions la Henriade de Voltaire, dont la France—ce me
semble—aurait pu se contenter.
J’ai toujours entendu dire que la Henriade est un poëme épique;—un
poëme épique est une chose dont on est fier, mais qu’on ne lit pas.
Je ne trouve pas que le peuple français,—en cette circonstance,—montre
un enthousiasme suffisamment frénétique.
On a cependant fait beaucoup d’annonces pour apprendre audit peuple
français l’événement qui devait le combler de joie.
Mais—entends donc,—peuple français, entends donc—la bonne
nouvelle.—Peuple français, tu as un poëme épique;—la nature non plus ne
se met guère en harmonie avec la circonstance,—l’hiver recommence,—les
sureaux et les chèvrefeuilles, qui étaient tombés dans le piége que leur
tendaient quelques rayons de soleil, ont vu sécher leurs premières feuilles
déjà sorties,—absolument comme si nous n’avions pas de poëme épique;—
mais qu’est-ce que cela te fait,—peuple français?—tu as un poëme épique;
—du reste, c’était le vrai moment d’en avoir un.
On s’occupe beaucoup à la Chambre et dans les journaux de la loi
sur la propriété littéraire.—On a déjà prononcé beaucoup de discours, on a
écrit de longues pages, et nous ne sommes pas au bout. Il y a quelques
années déjà,—au milieu d’une discussion sur le même sujet,—j’avais
proposé une loi, qui a été jugée, en ce temps-là, par les meilleurs esprits, si
simple, si raisonnable, qu’on n’y a pas trouvé la moindre objection. Ce
projet de loi, le voici,—j’ai lu tout ce qu’on a dit, tout ce qu’on a écrit sur la
question; il répond à tout:
ARTICLE UNIQUE. La propriété littéraire est une propriété.
Et cette propriété, une fois reconnue, rentrerait dans toutes les lois et
ordonnances relatives à la propriété en général. Cela est simple,—cela est
facile à trouver,—ce qui n’empêche pas que cela ne sera pas pris en la
moindre considération.
On a frappé de ridicule l’ancien amour romanesque,—qui attendait
cinq ans un regard,—cinq autres années un ruban,—cinq autres années un
baiser sur la main, et n’arrivait à recevoir le prix de son douloureux martyre
que lorsque ce prix était considérablement avarié et décrépit.—Cependant
l’amour ressemble beaucoup à un jardin au bout duquel on arriverait en
trois pas, si le chemin à faire n’était prolongé en une foule de petites allées
tournant capricieusement, fleuries et embaumées.
La nature avait donné à l’homme sa femelle, comme à tous les animaux,
—c’est l’homme qui a inventé la femme,—et c’est sa meilleure invention.
En ce temps-là, les romans et les romances ne vous peignaient que des
Amadis ténébreux et des Galaors mélancoliques—chantant leur martyre
dans leur délire, etc.
Aujourd’hui on a changé cela comme bien d’autres choses; les romans et
les romances ne représentent plus que des femmes méprisées,—se roulant,
se tordant aux genoux d’un homme,—ce qui est assez laid.
La même manie de changement qui a fait mettre sur les adresses le
numéro avant la rue,—a amené quelque chose de plus grave et de plus
satisfaisant pour la vanité des gens;—autrefois, quand on perdait un parent,
—la formule des lettres de faire part était celle-ci:
«Nous avons l’honneur de vous faire part de la perte de M..., etc.»
Puis, au bas de la lettre, en caractères plus petits, on ajoutait: «De la part
de M. et de M...»
Il est évident que le mort jouait le premier rôle et que les parents,
simples comparses,—n’avaient que le petit plaisir collectif et indirect
d’étaler les titres et les décorations de leur mort. Cela ne pouvait durer ainsi,
et on a changé la formule; on écrit aujourd’hui: «M..., chevalier de... de... et
de...; M. le président de..., madame la marquise de..., etc.;» puis, quand il
n’y a plus ni noms, ni titres, on ajoute au bas: «Ont l’honneur de vous faire
part de la mort de...»
Ce qui me paraît peu décent;—mais de ce temps-ci tout le monde veut
tellement paraître, qu’on est jaloux de l’attention posthume qu’usurpe le
pauvre mort.
J’ai sous les yeux un exemple curieux de ce nouvel usage. Il s’agit de la
mort de M. le baron Bl*** de B***, mort à Versailles.—Eh bien! si, averti
par l’encadrement noir de la lettre, vous voulez savoir lequel de vos amis
vous avez à regretter, il faut lire d’abord dix-sept noms suivis chacun de
deux à trois lignes de titres et de décorations en petit texte, avant d’arriver
au nom du mort, que rien ne sépare des noms de ses parents, afin qu’il soit
impossible de le lire sans avoir préalablement lu les autres. Mais il s’est
glissé dans cette lettre une singulière erreur:—on a confondu l’ancienne et
la nouvelle formule, et on s’y est considérablement embrouillé.
Dans l’ancienne formule—on mettait: «De la part de MM. tels et tels, de
mesdames telles et telles,—ses frère,—cousin,—neveu,—nièce, etc.»
Dans la nouvelle,—on doit mettre: «MM. et mesdames tels et telles vous
font part de la mort de M. Bl***de B***, leur frère, cousin, oncle, etc.»
Dans la lettre de faire part de M. Bl*** de B***, on a confondu les deux
formules,—et on dit: «MM. et mesdames tels et telles vous font part de la
mort de M. Bl*** de Bl***,—leur père, beau-père, etc.,—nièce et petite
nièce.»
De telle sorte que ce vieillard de quatre-vingt-trois ans se trouve, dans la
lettre qui annonce sa mort, être la nièce et la petite-nièce de mesdemoiselles
trois et quatre étoiles.
Je viens de lire dans un journal que feu M. de Quélen, l’archevêque
de Paris,—s’était adjoint—je ne sais plus quel prélat,—pour l’aider à
supporter le fardeau de l’épiscopat.—Cela me rappelle que je vois de temps
à autre dans d’autres feuilles et j’entends dire à la tribune—le poids des
affaires publiques,—le faix de la royauté,—etc., etc.
Ces phrases étaient bonnes à la rigueur et pouvaient espérer des dupes
quand il était d’usage de couvrir son ambition et son avidité d’un manteau
d’amour du bien public et de désintéressement;—mais elles sont bien
ridicules aujourd’hui—que l’on joue les plus vilains jeux, cartes sur table.
UN BIENFAITEUR A BON MARCHÉ.—Un homme fort riche se délasse
des travaux qu’il ne fait guère à la Chambre et de ceux qu’il fait faire à son
argent—par des amours cachées; modeste, il n’a pas la prétention d’être
aimé tout à fait pour ses avantages extérieurs. Il ne peut pas, comme César,
donner un royaume à la femme qu’il aime;—il n’a pas de royaume, et, s’il
en avait un, il ne le donnerait pas,—il le prêterait plutôt à quinze pour cent.
La belle, un de ces jours derniers,—était en conversation avec un rival
heureux de son bienfaiteur—lorsque tout à coup la sonnette se fait entendre.
—C’est lui!
M. de *** se trouble.
—N’aie pas peur, mon ami,—je l’aurai bientôt renvoyé: j’ai un moyen.
On cache l’ami dans un cabinet.—Le bienfaiteur arrive:
—J’ai sonné bien longtemps,—dit-il.
—J’étais occupée à mettre en ordre des mémoires;—je dois à tout le
monde,—vous êtes un horrible avare,—vous ne me donnez rien,—je suis
dans la misère.
—Mais, ma bonne...
—J’attends des fournisseurs,—des créanciers.
—Mais...
—Tenez, allez-vous-en,—je ne peux pas supporter votre présence.—
Allez-vous-en,—vous reviendrez demain.
Le bienfaiteur s’en va.—En sortant—il laisse clandestinement sur la
cheminée un billet de mille francs. La belle ne s’en aperçoit pas et le
reconduit—pour être plus certaine de son départ.
M. de ***, qui a vu le geste,—sort de sa cachette,—voit le billet de mille
francs et le met dans sa poche.
—Comment, mon cher ange, dit-il à la déesse,—tu es gênée et tu ne
m’en dis rien;—tu me caches tes chagrins, à moi qui serais si heureux de les
effacer!—mais c’est mal,—c’est très-mal!—Comment,—tu ne pouvais pas
me dire: «J’ai besoin d’argent.» Je suis bien en colère contre toi.—Tiens,
j’ai là un billet de mille francs,—je veux que tu le prennes;—je ne te
pardonnerai qu’à cette condition.
La belle hésite,—sans s’exposer cependant à être prise au mot.—M. de
*** insiste,—fait accepter le billet de mille francs de son rival,—et
s’échappe pour aller conter l’anecdote au foyer de l’Opéra.
M. le marquis de Basincourt, qui pendant les désastres de Lyon a
négligé ses propriétés pour celles des pauvres habitants, qui a sauvé à la
nage la vie de plusieurs personnes en danger,—a distribué de l’argent et du
pain à ceux que l’inondation avait le plus maltraités, a été nommé officier
de la Légion d’honneur.
C’est très-heureux et très-flatteur... pour la croix,—et c’est tout au plus si
elle le mérite.
A la Chapelle-Saint-Denis, le cimetière est tenu par un homme qui
n’a d’autre charge que d’enterrer les corps qui lui arrivent.—Il n’a pas de
registres, et, conséquemment, ne peut donner aucun renseignement.—Une
fois qu’il a mis ses morts en terre, tout est fini pour lui, et, à ce qu’il croit,
pour les autres, tellement que l’autre jour il trouvait fort mauvais la colère
où était un monsieur qui cherchait une fosse sans pouvoir la reconnaître; il
n’a jamais pu la lui indiquer.—Une autre personne, plus favorisée, a été
guidée par lui; mais, comme il ne va lui-même qu’au hasard, il l’a conduite
sur une tombe où était un autre mort que le sien,—ce dont elle ne s’est
aperçue—qu’après une assez considérable effusion de larmes pieuses.
Ce quiproquo de douleur rappelle ce qui se passa à Paris à l’église des
Petits-Pères—à l’époque du choléra:—on prenait les morts dans des
tapissières, où on en entassait une douzaine en ayant soin seulement de
numéroter les cercueils.
Arrivé à l’église, le cocher faisait porter chaque bière pendant quelques
instants dans le chœur.
Allons, nº 1;—les parents du nº 1, venez pleurer votre mort; assez pleuré
le nº 1;—passons au nº 2.
Allons, les parents du nº 2,—finissons-en, nous ne sommes pas ici pour
nous amuser,—dépêchons la douleur,—pleurons un peu vite.
Tout cela alla fort bien jusqu’au moment où on arriva au nº 6:—
comment distinguer le nº 6 du nº 9;—l’un de ces deux chiffres peut être
l’autre renversé.
A qui le mort?—voyons;—eh bien! les parents du nº 6 et les parents du
nº 9;—pleurez ensemble et partons.
Les Français ont eu longtemps un ridicule qu’on retrouve du reste
plus ou moins chez les autres peuples,—c’est la prétention d’être
invincibles.—On en a vu récemment une dernière manifestation lorsque
messieurs les députés s’emportèrent si fort contre M. Bugeaud, qui avait osé
dire que les Français avaient été quelquefois battus dans le commencement
des guerres de la République.
Remarquons en passant, à propos de M. Bugeaud,—que son
discours en faveur de la paix a été récompensé par un commandement
militaire.
Revenons à notre sujet:—la nouvelle prétention des Français est
aujourd’hui d’être humiliés, insultés, foulés aux pieds;—vous avez vu le
gâchis où ont failli nous mettre M. Thiers et les affaires d’Orient;—depuis
ce temps il est impossible qu’un cuisinier anglais fasse une sauce,—qu’un
serf russe coupe un arbre,—sans que les journaux annoncent à la France que
c’est dans l’intention de l’insulter;—les bonnes gens le croient et sont prêts
à crier comme le père du Cid:
C’en est fait,—prends ma vie avec un tel affront,
Le premier dont ma race ait vu rougir son front.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com