summaryrefslogtreecommitdiffstats
path: root/all_pairs/source/anagram
diff options
context:
space:
mode:
authorJoshua Bakita <bakitajoshua@gmail.com>2019-10-07 19:13:39 -0400
committerJoshua Bakita <bakitajoshua@gmail.com>2019-10-07 19:13:39 -0400
commit386b7d3366f1359a265da207a9cafa3edf553b64 (patch)
treec76120c2c138faed822e4ae386be6ef22a738a78 /all_pairs/source/anagram
parent54a3f7091a2146b29c73a6fdc4b62a5c4ad7a3d8 (diff)
Reorganize and commit all the modified TACLeBench code and run scripts
Diffstat (limited to 'all_pairs/source/anagram')
-rw-r--r--all_pairs/source/anagram/ChangeLog.txt125
-rw-r--r--all_pairs/source/anagram/anagram.c670
-rw-r--r--all_pairs/source/anagram/anagramTest.txt100
-rw-r--r--all_pairs/source/anagram/anagram_compare.h27
-rw-r--r--all_pairs/source/anagram/anagram_ctype.h45
-rw-r--r--all_pairs/source/anagram/anagram_input.c2317
-rw-r--r--all_pairs/source/anagram/anagram_stdlib.c153
-rw-r--r--all_pairs/source/anagram/anagram_stdlib.h29
-rw-r--r--all_pairs/source/anagram/anagram_strings.h27
9 files changed, 3493 insertions, 0 deletions
diff --git a/all_pairs/source/anagram/ChangeLog.txt b/all_pairs/source/anagram/ChangeLog.txt
new file mode 100644
index 0000000..fdba1cc
--- /dev/null
+++ b/all_pairs/source/anagram/ChangeLog.txt
@@ -0,0 +1,125 @@
1File: anagram.c
2Original provenience: unknown
3Source: unknown
4
52017-04-18:
6- Annotated anagram_main as entry-point for timing analysis
7
82016-06-22:
9- Fixed type signature of function anagram_main to conform to TACLeBench
10 standard, i.e. `void anagram_main (void)`.
11
122016-05-24:
13- Changed type of global variables anagram_achPhrase and
14 anagram_dictionary to `char const *[]`.
15- Changed parameter type of function anagram_BuildMask to
16 `char const *`.
17
182016-04-26:
19- Fixed array out-of-bounds access introduced by earlier change.
20
212016-04-20:
22- Fixed some compiler warnings.
23- Return value of anagram_return depends on the computation inside
24 of anagram_main.
25
262016-03-22
27- Added forward declarations for all functions.
28- Renamed function main to anagram_main.
29- Added function anagram_init that calls anagram_ReadDict, removed
30 call to anagram_ReadDict from anagram_main.
31- Added function anagram_return that handles the return value.
32- Added new function main that first calls anagram_init,
33 then anagram_main and finally returns the return value of
34 anagram_return.
35- Added generic TACLeBench header to all files.
36- Introduced comments to split file in sections for type
37 definitions, forward declarations, global variables,
38 initialization-related and return-value-related functions,
39 core benchmark functions, and main routine.
40- Renamed ch2i, DICTWORDS, Quad, MASK_BITS, MAX_QUADS, MAXCAND,
41 MAXSOL, ALPHABET, Word, PWord, PPWord, apwCand, cpwCand, Letter,
42 PLetter, alPhrase, cchPhraseLength, aqMainMask, aqMainSign,
43 cchMinLength, auGlobalFrequency, achByFrequency, pchDictionary,
44 Reset, ReadDict, BuildMask, NewWord, NextWord, BuildWord,
45 AddWords, apwSol, cpwLast, OneStep, DumpWords, FindAnagram and
46 SortCandidates to anagram_ch2i, anagram_DICTWORDS, anagram_Quad,
47 anagram_MASK_BITS, anagram_MAX_QUADS, anagram_MAXCAND,
48 anagram_MAXSOL, anagram_ALPHABET, anagram_Word, anagram_PWord,
49 anagram_PPWord, anagram_apwCand, anagram_cpwCand, anagram_Letter,
50 anagram_PLetter, anagram_alPhrase, anagram_cchPhraseLength,
51 anagram_aqMainMask, anagram_aqMainSign, anagram_cchMinLength,
52 anagram_auGlobalFrequency, anagram_achByFrequency,
53 anagram_pchDictionary, anagram_Reset, anagram_ReadDict,
54 anagram_BuildMask, anagram_NewWord, anagram_NextWord,
55 anagram_BuildWord, anagram_AddWords, anagram_apwSol,
56 anagram_cpwLast, anagram_OneStep, anagram_DumpWords,
57 anagram_FindAnagram and anagram_SortCandidates.
58- Renamed swapi, pivot, qsorts, simulated_heap and freeHeapPos to
59 anagram_swapi, anagram_pivot, anagram_qsorts,
60 anagram_simulated_heap and anagram_freeHeapPos.
61- Renamed achPhrase and dictionary to anagram_achPhrase and
62 anagram_dictionary.
63- Renamed CompareFrequency to anagram_CompareFrequency.
64- Increased simulated heap in anagram_stdlib.c to 18000 bytes to
65 prevent segmentation fault.
66- Changed header guard _WCCMALLOC_H to ANAGRAM_STRINGS_H.
67- Renamed wccmalloc, wccbzero to anagram_malloc, anagram_bzero.
68- Moved declaration of anagram_malloc to header anagram_stdlib.h.
69- Introduced header guard ANAGRAM_CTYPE_H.
70- Renamed wccislower, wccisupper, wccisalpha, wcctolower to
71 anagram_islower, anagram_isupper, anagram_isalpha,
72 anagram_tolower.
73- Removed illegal keyword "inline".
74- Changed header guard _WCCSTDLIB_H to ANAGRAM_STDLIB_H.
75- Renamed wccqsort to anagram_qsort.
76- Fixed compiler warning "no previous extern declaration for
77 non-static variable" for variables simulated_heap and
78 freeHeapPos by declaring them static.
79- Renamed preprocessor define HEAP_SIZE to ANAGRAM_HEAP_SIZE.
80- Fixed compiler warning "no previous prototype for function" by
81 moving includes to the top of the file.
82- Fixed compiler warnings "implicit conversion changes signedness"
83 and "comparison of integers of different signs" by consistenly
84 using the type unsigned long in qsort helper functions.
85- Moved function CompareFrequency to file anagram.c, added
86 declaration for it in file anagram_compare.h and included it in
87 anagram_stdlib.h.
88- Fixed compiler warning "no previous extern declaration for
89 non-static variable" by adding forward declarations.
90- Fixed compiler warning "macro is not used" by removing unused
91 macros MAXWORDS and i2ch.
92- Replaced macro ch2i by proper function.
93- Fixed compiler warning "array subscript is of type 'char' in
94 function CompareFrequency.
95- Fixed compiler warning "unused variable" by removing variable i
96 in function Reset.
97- Fixed compiler warning "no previous extern declaration for
98 non-static variable" by making global variables in file
99 anagram.c static.
100- Replaced macro lPhrase by its expansion.
101- Fixed compiler warnings "implicit conversion loses integer
102 precision" and "implicit conversion changes signedness" by
103 adding explicit casts or using the appropriate type for local
104 variables.
105- Fixed compiler warning "array subscript is of type 'char'" by
106 changing type of some local variables as well as of global
107 variable achByFrequency to int.
108- Changed all //-style comments to /* */-style comments.
109- Moved contents of wccmalloc.c to anagram_stdlib.c.
110- Renamed input.c to anagram_input.c.
111- Renamed wccctype.h to anagram_ctype.h.
112- Renamed wccstdlib.c to anagram_stdlib.c.
113- Renamed wccstdlib.h to anagram_stdlib.h.
114- Renamed wccmalloc.h to anagram_strings.h.
115- Applied TACLeBench formatting rules via
116 astyle --options=doc/example/astylerc.txt
117- Tested conformance to C99 via
118 clang -fsyntax-only -Weverything -Wno-unknown-pragmas -Wno-padded -pedantic -std=c99
119
1202017-06-27
121- Remove static declarations.
122
1232017-07-10:
124- Adjust alignment calculation in anagram_malloc to not add padding on already
125 aligned addresses. This prevents a buffer overflow of anagram_simulated_heap.
diff --git a/all_pairs/source/anagram/anagram.c b/all_pairs/source/anagram/anagram.c
new file mode 100644
index 0000000..8f140a3
--- /dev/null
+++ b/all_pairs/source/anagram/anagram.c
@@ -0,0 +1,670 @@
1/*
2
3 This program is part of the TACLeBench benchmark suite.
4 Version 2.0
5
6 Name: anagram
7
8 Author: Raymond Chen
9
10 Function: A program that computes anagrams.
11
12 Source: See below.
13
14 Original name: anagram
15
16 Changes: See ChangeLog.txt
17
18 License: See below.
19
20*/
21
22/*
23 Anagram program by Raymond Chen,
24 inspired by a similar program by Brian Scearce
25
26 This program is Copyright 1991 by Raymond Chen.
27 (rjc@math.princeton.edu)
28
29 This program may be freely distributed provided all alterations
30 to the original are clearly indicated as such.
31*/
32
33/* There are two tricks. First is the Basic Idea:
34
35 When the user types in a phrase, the phrase is first preprocessed to
36 determine how many of each letter appears. A bit field is then constructed
37 dynamically, such that each field is large enough to hold the next power
38 of two larger than the number of times the character appears. For example,
39 if the phrase is hello, world, the bit field would be
40
41 00 00 00 000 000 00 00
42 d e h l o r w
43
44 The phrase hello, world, itself would be encoded as
45
46 01 01 01 011 010 01 01
47 d e h l o r w
48
49 and the word hollow would be encoded as
50
51 00 00 01 010 010 00 01
52 d e h l o r w