Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manpage #98

Merged
merged 7 commits into from
Sep 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions src/mmwtex.c
Original file line number Diff line number Diff line change
Expand Up @@ -5274,51 +5274,49 @@ flag writeBibliography(vstring bibFile,
/* **IMPORTANT** Make sure to update mmhlpa.c HELP WRITE BIBLIOGRAPHY
if new items are added to this list. */
if (0
/* Put the most frequent ones first to speed up search;
TODO: count occurrences in mmbiblio.html to find optimal order */
|| !strcmp(mid(str2, k, (long)strlen("THEOREM")), "THEOREM")
Copy link
Contributor

@wlammen wlammen Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list is searched sequentially. Matching an item at the beginning is obviously way more efficient (1 comparison) than one at the end (40 comparisons). So if you know, the keyword in str2 is 'theorem' 70% of the time, it makes some sense, to have it at the beginning. This is the gist of the deleted comment here. I think, the first 5 elements of the old list were deliberately put in the early position for speed up. The tail starting with 'AXIOM' are matched fairly seldom, so their exact position does not really matter, and we can keep an alphabetic order there, without compromising speed to a noticeable degree.

What do I personally think of it? Well, if search time really matters, than there are better strategies around, like binary search, for example. This is a poor man's optimization. It may have an improving effect, though, depending on how often a search is called. Without knowing details, I would keep the first five elements, but order the tail.

The 0 in the beginning of the list is likely optimized out and just there to keep all items, including the first, in the same textual format.

Copy link
Contributor

@wlammen wlammen Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a technical point of view, I do not object to this PR any more, unless you see a slow down due to the impoverished search.
Maybe one should add a
// ---- end of optimized search -----
in between head and tail of the list, for better understanding.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know C well enough, so I rely on you here. What order do you prefer ? Is the following ok (including comments) ?

           /* **IMPORTANT** Make sure to update mmhlpa.c HELP WRITE BIBLIOGRAPHY
              if new items are added to this list. */
           if (0
              /* The first five keywords are more frequent so are put first for
                  efficiency; the rest is in alphabetical order. */
              || !strcmp(mid(str2, k, (long)strlen("THEOREM")), "THEOREM")
              || !strcmp(mid(str2, k, (long)strlen("EQUATION")), "EQUATION")
              || !strcmp(mid(str2, k, (long)strlen("DEFINITION")), "DEFINITION")
              || !strcmp(mid(str2, k, (long)strlen("LEMMA")), "LEMMA")
              || !strcmp(mid(str2, k, (long)strlen("EXERCISE")), "EXERCISE")
              // ---- end of optimized search -----
              ... [alphabetical]

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. That's the content of my latest commit. So I guess you can approve. (On this repository, I have no right to approve or merge --- and am not asking for one.)

|| !strcmp(mid(str2, k, (long)strlen("EQUATION")), "EQUATION")
|| !strcmp(mid(str2, k, (long)strlen("DEFINITION")), "DEFINITION")
|| !strcmp(mid(str2, k, (long)strlen("LEMMA")), "LEMMA")
|| !strcmp(mid(str2, k, (long)strlen("EXERCISE")), "EXERCISE")
|| !strcmp(mid(str2, k, (long)strlen("AXIOM")), "AXIOM")
|| !strcmp(mid(str2, k, (long)strlen("CLAIM")), "CLAIM")
|| !strcmp(mid(str2, k, (long)strlen("CHAPTER")), "CHAPTER")
|| !strcmp(mid(str2, k, (long)strlen("CLAIM")), "CLAIM")
|| !strcmp(mid(str2, k, (long)strlen("COMPARE")), "COMPARE")
|| !strcmp(mid(str2, k, (long)strlen("CONCLUSION")), "CONCLUSION")
|| !strcmp(mid(str2, k, (long)strlen("CONDITION")), "CONDITION")
|| !strcmp(mid(str2, k, (long)strlen("CONJECTURE")), "CONJECTURE")
|| !strcmp(mid(str2, k, (long)strlen("COROLLARY")), "COROLLARY")
|| !strcmp(mid(str2, k, (long)strlen("CRITERIA")), "CRITERIA")
|| !strcmp(mid(str2, k, (long)strlen("CRITERION")), "CRITERION")
|| !strcmp(mid(str2, k, (long)strlen("DEFINITION")), "DEFINITION")
|| !strcmp(mid(str2, k, (long)strlen("EQUATION")), "EQUATION")
|| !strcmp(mid(str2, k, (long)strlen("EXAMPLE")), "EXAMPLE")
|| !strcmp(mid(str2, k, (long)strlen("EXERCISE")), "EXERCISE")
|| !strcmp(mid(str2, k, (long)strlen("FACT")), "FACT")
|| !strcmp(mid(str2, k, (long)strlen("FIGURE")), "FIGURE")
|| !strcmp(mid(str2, k, (long)strlen("INTRODUCTION")), "INTRODUCTION")
|| !strcmp(mid(str2, k, (long)strlen("ITEM")), "ITEM")
|| !strcmp(mid(str2, k, (long)strlen("LEMMA")), "LEMMA")
|| !strcmp(mid(str2, k, (long)strlen("LEMMAS")), "LEMMAS")
|| !strcmp(mid(str2, k, (long)strlen("LINE")), "LINE")
|| !strcmp(mid(str2, k, (long)strlen("LINES")), "LINES")
|| !strcmp(mid(str2, k, (long)strlen("NOTATION")), "NOTATION")
|| !strcmp(mid(str2, k, (long)strlen("NOTE")), "NOTE")
|| !strcmp(mid(str2, k, (long)strlen("OBSERVATION")), "OBSERVATION")
|| !strcmp(mid(str2, k, (long)strlen("PARAGRAPH")), "PARAGRAPH")
|| !strcmp(mid(str2, k, (long)strlen("PART")), "PART")
|| !strcmp(mid(str2, k, (long)strlen("POSTULATE")), "POSTULATE")
|| !strcmp(mid(str2, k, (long)strlen("PROBLEM")), "PROBLEM")
|| !strcmp(mid(str2, k, (long)strlen("PROOF")), "PROOF")
|| !strcmp(mid(str2, k, (long)strlen("PROPERTY")), "PROPERTY")
|| !strcmp(mid(str2, k, (long)strlen("PROPOSITION")), "PROPOSITION")
|| !strcmp(mid(str2, k, (long)strlen("REMARK")), "REMARK")
|| !strcmp(mid(str2, k, (long)strlen("RESULT")), "RESULT")
|| !strcmp(mid(str2, k, (long)strlen("RULE")), "RULE")
|| !strcmp(mid(str2, k, (long)strlen("SCHEME")), "SCHEME")
|| !strcmp(mid(str2, k, (long)strlen("SECTION")), "SECTION")
|| !strcmp(mid(str2, k, (long)strlen("PROOF")), "PROOF")
|| !strcmp(mid(str2, k, (long)strlen("STATEMENT")), "STATEMENT")
|| !strcmp(mid(str2, k, (long)strlen("CONCLUSION")), "CONCLUSION")
|| !strcmp(mid(str2, k, (long)strlen("FACT")), "FACT")
|| !strcmp(mid(str2, k, (long)strlen("INTRODUCTION")), "INTRODUCTION")
|| !strcmp(mid(str2, k, (long)strlen("PARAGRAPH")), "PARAGRAPH")
|| !strcmp(mid(str2, k, (long)strlen("SCOLIA")), "SCOLIA")
|| !strcmp(mid(str2, k, (long)strlen("SCOLION")), "SCOLION")
|| !strcmp(mid(str2, k, (long)strlen("SECTION")), "SECTION")
|| !strcmp(mid(str2, k, (long)strlen("STATEMENT")), "STATEMENT")
|| !strcmp(mid(str2, k, (long)strlen("SUBSECTION")), "SUBSECTION")
|| !strcmp(mid(str2, k, (long)strlen("TABLE")), "TABLE")
|| !strcmp(mid(str2, k, (long)strlen("CRITERION")), "CRITERION")
|| !strcmp(mid(str2, k, (long)strlen("CRITERIA")), "CRITERIA")
|| !strcmp(mid(str2, k, (long)strlen("THEOREM")), "THEOREM")
) {
m = k;
break;
Expand Down