Add second year

This commit is contained in:
2023-12-07 01:19:12 +00:00
parent 3291e5c79e
commit 3d12031ab8
1168 changed files with 431409 additions and 0 deletions

View File

@ -0,0 +1,49 @@
\addtolength{\hoffset}{-2.25cm}
\addtolength{\textwidth}{4.5cm}
\addtolength{\voffset}{-3.25cm}
\addtolength{\textheight}{5cm}
\setlength{\parskip}{0pt}
\setlength{\parindent}{0in}
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\usepackage{blindtext} % Package to generate dummy text
\usepackage{charter} % Use the Charter font
\usepackage[utf8]{inputenc} % Use UTF-8 encoding
\usepackage{microtype} % Slightly tweak font spacing for aesthetics
\usepackage[english, ngerman]{babel} % Language hyphenation and typographical rules
\usepackage{amsthm, amsmath, amssymb} % Mathematical typesetting
\usepackage{float} % Improved interface for floating objects
\usepackage[final, colorlinks = true,
linkcolor = black,
citecolor = black]{hyperref} % For hyperlinks in the PDF
\usepackage{graphicx, multicol} % Enhanced support for graphics
\usepackage{xcolor} % Driver-independent color extensions
\usepackage{marvosym, wasysym} % More symbols
\usepackage{rotating} % Rotation tools
\usepackage{censor} % Facilities for controlling restricted text
\usepackage{listings, style/lstlisting} % Environment for non-formatted code, !uses style file!
\usepackage{pseudocode} % Environment for specifying algorithms in a natural way
\usepackage{style/avm} % Environment for f-structures, !uses style file!
\usepackage{booktabs} % Enhances quality of tables
\usepackage{tikz-qtree} % Easy tree drawing tool
\tikzset{every tree node/.style={align=center,anchor=north},
level distance=2cm} % Configuration for q-trees
\usepackage{style/btree} % Configuration for b-trees and b+-trees, !uses style file!
\usepackage[backend=biber,style=numeric,
sorting=nyt]{biblatex} % Complete reimplementation of bibliographic facilities
\addbibresource{ecl.bib}
\usepackage{csquotes} % Context sensitive quotation facilities
\usepackage[yyyymmdd]{datetime} % Uses YEAR-MONTH-DAY format for dates
\renewcommand{\dateseparator}{-} % Sets dateseparator to '-'
\usepackage{fancyhdr} % Headers and footers
\pagestyle{fancy} % All pages have headers and footers
\fancyhead{}\renewcommand{\headrulewidth}{0pt} % Blank out the default header
\fancyfoot[L]{} % Custom footer text
\fancyfoot[C]{} % Custom footer text
\fancyfoot[R]{\thepage} % Custom footer text
\newcommand{\note}[1]{\marginpar{\scriptsize \textcolor{red}{#1}}} % Enables comments in red on margin
%----------------------------------------------------------------------------------------

View File

@ -0,0 +1,87 @@
<?xml version="1.0" standalone="yes"?>
<!-- logreq request file -->
<!-- logreq version 1.0 / dtd version 1.0 -->
<!-- Do not edit this file! -->
<!DOCTYPE requests [
<!ELEMENT requests (internal | external)*>
<!ELEMENT internal (generic, (provides | requires)*)>
<!ELEMENT external (generic, cmdline?, input?, output?, (provides | requires)*)>
<!ELEMENT cmdline (binary, (option | infile | outfile)*)>
<!ELEMENT input (file)+>
<!ELEMENT output (file)+>
<!ELEMENT provides (file)+>
<!ELEMENT requires (file)+>
<!ELEMENT generic (#PCDATA)>
<!ELEMENT binary (#PCDATA)>
<!ELEMENT option (#PCDATA)>
<!ELEMENT infile (#PCDATA)>
<!ELEMENT outfile (#PCDATA)>
<!ELEMENT file (#PCDATA)>
<!ATTLIST requests
version CDATA #REQUIRED
>
<!ATTLIST internal
package CDATA #REQUIRED
priority (9) #REQUIRED
active (0 | 1) #REQUIRED
>
<!ATTLIST external
package CDATA #REQUIRED
priority (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8) #REQUIRED
active (0 | 1) #REQUIRED
>
<!ATTLIST provides
type (static | dynamic | editable) #REQUIRED
>
<!ATTLIST requires
type (static | dynamic | editable) #REQUIRED
>
<!ATTLIST file
type CDATA #IMPLIED
>
]>
<requests version="1.0">
<internal package="biblatex" priority="9" active="0">
<generic>latex</generic>
<provides type="dynamic">
<file>main.bcf</file>
</provides>
<requires type="dynamic">
<file>main.bbl</file>
</requires>
<requires type="static">
<file>blx-dm.def</file>
<file>blx-compat.def</file>
<file>biblatex.def</file>
<file>standard.bbx</file>
<file>numeric.bbx</file>
<file>numeric.cbx</file>
<file>biblatex.cfg</file>
<file>german.lbx</file>
<file>ngerman.lbx</file>
<file>english.lbx</file>
</requires>
</internal>
<external package="biblatex" priority="5" active="0">
<generic>biber</generic>
<cmdline>
<binary>biber</binary>
<infile>main</infile>
</cmdline>
<input>
<file>main.bcf</file>
</input>
<output>
<file>main.bbl</file>
</output>
<provides type="dynamic">
<file>main.bbl</file>
</provides>
<requires type="dynamic">
<file>main.bcf</file>
</requires>
<requires type="editable">
<file>ecl.bib</file>
</requires>
</external>
</requests>

View File

@ -0,0 +1,383 @@
\documentclass[a4paper]{article}
\input{head}
\begin{document}
%-------------------------------
% TITLE SECTION
%-------------------------------
\fancyhead[C]{}
\hrule \medskip % Upper rule
\begin{minipage}{0.295\textwidth}
\raggedright
\footnotesize
Andrew Hayes \hfill\\
21321503 \hfill\\
a.hayes18@nuigalway.ie
\end{minipage}
\begin{minipage}{0.4\textwidth}
\centering
\large
CT255 Assignment 3\\
\normalsize
Steganography\\
\end{minipage}
\begin{minipage}{0.295\textwidth}
\raggedleft
\today\hfill\\
\end{minipage}
\medskip\hrule
\bigskip
%-------------------------------
% CONTENTS
%-------------------------------
\section{Problem 1}
\subsection{Code}
\begin{lstlisting}[language=Java]
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Pattern;
public class Stegano1
{
public static void main(String[] args) {
// Strings to hold the arguments. mode is either A or E for "Add" or "Extract".
String mode, inputfile, outputfile, bitstring;
Boolean err = false; // Boolean to tell if the arguments were passed correctly or not
if (args.length > 1) { // checking that at least one argument was passed to main
// assigning the mode & inputfile arguments
mode = args[0];
inputfile = args[1];
if (inputfile.equals("")) { // checking that an inputfile was provided (String was not empty)
err = true;
}
else if ((mode.equals("A")) && (args.length > 3)){ // checking if the mode is "Add" & that the number of arguments provided was greater than 3
// assigning the outputfile & bitstring arguments
outputfile = args[2];
bitstring = args[3];
if (outputfile.equals("") || bitstring.equals("")) { // checking that neither the outputfile nor bitstring were empty strings
err = true;
}
else {
// hiding the bitstring
hide(inputfile, outputfile, bitstring);
}
}
else if (mode.equals("E")){ // checking if the mode is "Extract"
// retrieving (extracting) the bitstring from text
retrieve(inputfile);
}
else {
err = true;
}
}
else {
err = true;
}
if (err) {
System.out.println();
System.out.println("Use: Stegano1 <A:E><Input File><OutputFile><Bitstring>");
System.out.println("Example to add a bitvector to a file: Stegano1 A inp.txt out.txt 0010101");
System.out.println("Example to extract a bitvector from a file: Stegano1 E inp.txt");
}
}
// method to hide a bitstring in a copy the input file provided
static void hide(String inpFile, String outFile, String bitString) {
BufferedReader reader; // declaring a BufferedReader for the input file
BufferedWriter writer; // declaring a BufferedWriter for the output file
try {
// initialising the reader & writer to FileReaders of their respective files (inpFile & outFile)
reader = new BufferedReader(new FileReader(inpFile));
writer = new BufferedWriter(new FileWriter(outFile));
String line = reader.readLine(); // reading in the first line from the input file
// will loop until there are no more lines to be read in from the input file (inpFile)
while (line != null) {
// if the bitString is not (yet) an empty String
if (!bitString.equals("")) {
// if the first bit (char) of the bitString is 0
if (bitString.charAt(0) == '0') { // note: must use '' instead of "" for char literals
line = line.concat(" "); // concatenating a space to the end of the line (one space represents a 0)
}
// if the first bit of the bitString is 1
if (bitString.charAt(0) == '1') {
line = line.concat(" "); // concatenating two spaces to the end of the line (two spaces represents a 1)
}
// removing the first bit from the bitString now that it has been used
bitString = bitString.substring(1, bitString.length()); // replacing bitString with it's substring that goes from the second character to the last character
}
// writing the amended line to the output file
writer.write(line);
writer.newLine();
// reading the next line
line = reader.readLine();
}
// closing the reader & the writer
reader.close();
writer.close();
}
// catching any IOExceptions
catch (IOException e) {
e.printStackTrace();
}
}
// method to retrieve a hidden string from the input file provided
static void retrieve(String inpFile) {
BufferedReader reader; // declaring a BufferedReader for the input file (inpFile)
String message = "";
try {
reader = new BufferedReader(new FileReader(inpFile)); // initialising the reader to a FileReader of the input file (inpFile)
String line = reader.readLine(); // reading in the first line from the input file
// will loop until there are no more lines to be read in from the input file
while (line != null) {
// checking if the line ends in a space using a regular expression
if (Pattern.matches(".* $", line)) { // (checking if the String line contains any amount of any characters, followed by a space followed by the end of a line)
// checking if the line ends in two spaces using a regular expression
if (Pattern.matches(".* $", line)) { // (checking if the String line contains any amount of any characters, followed by two spaces followed by the end of a line)
message = message.concat("1"); // concatenating a "1" onto the message String (two spaces represent a "1")
}
else { // essentially, this "else" means "if the line ends with one space but not two"
message = message.concat("0"); // concatenating a "0" onto the message String (one space represents a "0")
}
}
else { // if the String does not end in a space, then there is no (more) message to read
break;
}
// reading the next line
line = reader.readLine();
}
// closing in the reader
reader.close();
// checking if the message String is empty so that an error message can be printed if no hidden message was found
if (message.equals("")) {
message = "Error: No hidden message found!";
}
// printing out the message
System.out.println(message);
}
// catching any IOExceptions
catch (IOException e) {
e.printStackTrace();
}
}
}
\end{lstlisting}
\subsection{Screenshot of Compilation \& Output}
\includegraphics[width = 15cm]{output1.png}
\bigskip
%------------------------------------------------
\section{Problem 2}
\subsection{Code}
\begin{lstlisting}[language=java]
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Pattern;
public class Stegano1
{
public static void main(String[] args) {
// Strings to hold the arguments. mode is either A or E for "Add" or "Extract".
String mode, inputfile, outputfile, bitstring;
Boolean err = false; // Boolean to tell if the arguments were passed correctly or not
if (args.length > 1) { // checking that at least one argument was passed to main
// assigning the mode & inputfile arguments
mode = args[0];
inputfile = args[1];
if (inputfile.equals("")) { // checking that an inputfile was provided (String was not empty)
err = true;
}
else if ((mode.equals("A")) && (args.length > 3)){ // checking if the mode is "Add" & that the number of arguments provided was greater than 3
// assigning the outputfile & bitstring arguments
outputfile = args[2];
bitstring = args[3];
if (outputfile.equals("") || bitstring.equals("")) { // checking that neither the outputfile nor bitstring were empty strings
err = true;
}
else {
// hiding the bitstring
hide(inputfile, outputfile, bitstring);
}
}
else if (mode.equals("E")){ // checking if the mode is "Extract"
// retrieving (extracting) the bitstring from text
retrieve(inputfile);
}
else {
err = true;
}
}
else {
err = true;
}
if (err) {
System.out.println();
System.out.println("Use: Stegano1 <A:E><Input File><OutputFile><Bitstring>");
System.out.println("Example to add a bitvector to a file: Stegano1 A inp.txt out.txt 0010101");
System.out.println("Example to extract a bitvector from a file: Stegano1 E inp.txt");
}
}
// method to hide a bitstring in a copy the input file provided
static void hide(String inpFile, String outFile, String bitString) {
// to encode 2 bits with just one symbol, i'm going to represent the binary digits as an analog represenation of the number it represents plus one
// e.g., 00 will be represented as " " (1 space), 01 as " " (2 spaces), 10 as " " (3 spaces), and 11 as " " (4 spaces)
// the two bits are treated as a binary number, and then i add one to said binary number to get the number of spaces that will represent that number
BufferedReader reader; // declaring a BufferedReader for the input file
BufferedWriter writer; // declaring a BufferedWriter for the output file
try {
// initialising the reader & writer to FileReaders of their respective files (inpFile & outFile)
reader = new BufferedReader(new FileReader(inpFile));
writer = new BufferedWriter(new FileWriter(outFile));
String line = reader.readLine(); // reading in the first line from the input file
// checking if the number of bits in the bitstring is uneven, and if so, adding a '0' onto the end
if (bitString.length() % 2 != 0) { bitString = bitString.concat("0"); }
// will loop until there are no more lines to be read in from the input file (inpFile)
while (line != null) {
// if the bitString is not (yet) an empty String
if (!bitString.equals("")) {
// if the first 2-bit substring is 00, adding one space to the end of the line
if (bitString.substring(0,2).equals("00")) {
line = line.concat(" ");
}
// if the first 2-bit substring is 01, adding two spaces to the end of the line
else if (bitString.substring(0,2).equals("01")) {
line = line.concat(" ");
}
// if the first 2-bit substring is 10, adding three spaces to the end of the line
else if (bitString.substring(0,2).equals("10")) {
line = line.concat(" ");
}
// if the first 2-bit substring is 11, adding four spaces to the end of the line
else if (bitString.substring(0,2).equals("11")) {
line = line.concat(" ");
}
// removing the first two bits from the bitString now that they have been used
bitString = bitString.substring(2, bitString.length()); // replacing bitString with it's substring that goes from the third character to the last character
}
// writing the amended line to the output file
writer.write(line);
writer.newLine();
// reading the next line
line = reader.readLine();
}
// closing the reader & the writer
reader.close();
writer.close();
}
// catching any IOExceptions
catch (IOException e) {
e.printStackTrace();
}
}
// method to retrieve a hidden string from the input file provided
static void retrieve(String inpFile) {
BufferedReader reader; // declaring a BufferedReader for the input file (inpFile)
String message = "";
try {
reader = new BufferedReader(new FileReader(inpFile)); // initialising the reader to a FileReader of the input file (inpFile)
String line = reader.readLine(); // reading in the first line from the input file
// will loop until there are no more lines to be read in from the input file
while (line != null) {
// checking if the line ends in a space using a regular expression
if (Pattern.matches(".* $", line)) { // (checking if the String line contains any amount of any characters, followed by a space followed by the end of a line)
if (Pattern.matches(".* $", line)) { // checking if the line ends in four spaces using a regular expression
message = message.concat("11"); // concatenating "11" onto the end of the message String (four spaces represents "11")
}
else if (Pattern.matches(".* $", line)) { // checking if the line ends in three spaces using a regular expression
message = message.concat("10"); // concatenating "10" onto the end of the message String (three spaces represents "10")
}
else if (Pattern.matches(".* $", line)) { // (checking if the String line contains any amount of any characters, followed by two spaces followed by the end of a line)
message = message.concat("01"); // concatenating a "1" onto the message String (two spaces represent a "1")
}
else { // essentially, this "else" means "if the line ends with one space but not two"
message = message.concat("00"); // concatenating a "0" onto the message String (one space represents a "0")
}
}
else { // if the String does not end in a space, then there is no (more) message to read
break;
}
// reading the next line
line = reader.readLine();
}
// closing in the reader
reader.close();
// checking if the message String is empty so that an error message can be printed if no hidden message was found
if (message.equals("")) {
message = "Error: No hidden message found!";
}
// printing out the message
System.out.println(message);
}
// catching any IOExceptions
catch (IOException e) {
e.printStackTrace();
}
}
}
\end{lstlisting}
\subsection{Output}
\includegraphics[width = 15cm]{output2.png}
\end{document}

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -0,0 +1,165 @@
% avm.sty -- for attribute-value matrices -- mar 29, 1992; rev. dec 6, 1993
% (c) 1992 christopher manning (manning@csli.stanford.edu) -- see avm.doc.tex
\newif\ifavmactive\newif\ifavmsorted\newif\ifavmlabeled
\newif\ifavmcenter\newif\ifavmbottom
\newif\ifavmbottomright\newif\ifavmtopleft\newif\ifavmtopright
\newdimen\avmdimen
\newbox\avmboxone\newbox\avmboxthree
\def\avmoptions#1{\avmactivefalse\avmsortedfalse\avmlabeledfalse
\avmcenterfalse\avmbottomfalse
\avmbottomrightfalse\avmtopleftfalse\avmtoprightfalse
\def\more{#1}\ifx\more\empty\else\avmjoptions#1,\@nil\fi}
\def\avmjoptions#1,#2\@nil{\def\more{#2}\csname avm#1true\endcsname
\ifx\more\empty\else\avmjoptions#2\@nil\fi}
\def\avmfont#1{\def\avmjfont{#1}}
\def\avmjfont{}
\def\avmvalfont#1{\def\avmjvalfont{#1}}
\def\avmjvalfont{}
\def\avmsortfont#1{\def\avmjsortfont{#1}}
\def\avmjsortfont{}
\def\avmhskip#1{\def\avmjhskip{#1}}
\def\avmjhskip{1em}
\def\avmbskip#1{\def\avmjbskip{#1}}
\def\avmjbskip{0em}
\def\avmvskip#1{\def\avmjvskip{#1}}
\def\avmjvskip{0.385ex}%was .3875
\def\avmjprolog#1{$\mskip-\thinmuskip
\left#1\hskip\avmjbskip\vcenter\bgroup\vskip\avmjvskip
\ialign\bgroup\avmjfont
\strut ##\unskip\hfil
&&\hskip\avmjhskip\avmjvalfont ##\unskip\hfil\cr}
\def\avmjpostlog#1{\crcr\egroup\vskip\avmjvskip\egroup
\hskip\avmjbskip\right#1\mskip-\thinmuskip$\ignorespaces}
\def\avmjcatcode{\let\lparen=(\let\rparen=)\catcode`\[=13\catcode`\]=13
\catcode`\<=13\catcode`\@=13\catcode`\(=13\catcode`\)=13
\catcode`\>=13\catcode`\|=13}
{\avmjcatcode % new group: redefine above catcodes as active
\gdef\specialavm{\avmjcatcode
\def({\avmjprolog\lparen}%
\def){\avmjpostlog\rparen}%
\def<{\avmjprolog\langle}%
\def>{\avmjpostlog\rangle}%
\ifavmsorted
\def[##1{\setbox\avmboxthree=\hbox{\avmjsortfont##1\/}\setbox2=\hbox
\bgroup\avmjprolog\lbrack}%
\def]{\avmjpostlog\rbrack\egroup\avmjsort}%
\else\ifavmlabeled
\def[##1{\def\more{##1}\setbox2=\hbox\bgroup\avmjprolog[}%
\def]{\avmjpostlog]\egroup\node{\more}{\box2}}%
\else
\def[{\avmjprolog\lbrack}%
\def]{\avmjpostlog\rbrack}%
\fi\fi
%
\def\<{$\langle$}\def\>{$\rangle$}%
\def\({\lparen}\def\){\rparen}%
\def\[{\lbrack}\def\]{\rbrack}%
\def|{$\,\vert\,$}%
\def@##1{\avmbox{##1}}%
} % end defn of \specialavm
} % restore active catcodes
\long\def\avm{\begingroup
\ifavmactive\specialavm
\else
\def\({\avmjprolog(}%
\def\){\avmjpostlog)}%
\def\<{\avmjprolog\langle}%
\def\>{\avmjpostlog\rangle}%
%
\ifavmsorted
\def\[##1{\setbox\avmboxthree=\hbox{\avmjsortfont##1\/}\setbox
2=\hbox\bgroup\avmjprolog[}%
\def\]{\avmjpostlog]\egroup\avmjsort}%
\else\ifavmlabeled
\def\[##1{\def\more{##1}\setbox2=\hbox\bgroup\avmjprolog[}%
\def\]{\avmjpostlog]\egroup\node{\more}{\box2}}%
\else
\def\[{\avmjprolog[}%
\def\]{\avmjpostlog]}%
\fi\fi
%
\def\|{$\,\vert\,$}%
\def\@##1{\avmbox{##1}}%
\fi % end not active
%
\ifx\LaTeX\undefined\def\\{\cr}% running under TeX
\else \def\\{\@tabularcr}% Leverage off LaTeX's \\*[dimen] options
\fi
\def\!{\node}%
\long\def\avmjsort{\dimen2=\ht2\advance\dimen2 by -.25\baselineskip
\global\dimen\avmdimen=\wd\avmboxthree
\ifavmtopleft \raise\dimen2\llap{\box\avmboxthree}\box2%
\else\ifavmtopright \box2\raise\dimen2\box\avmboxthree%
\else\ifavmbottomright \box2\lower\dimen2\box\avmboxthree%
\else \lower\dimen2\llap{\box\avmboxthree}\box2%
\fi\fi\fi}%
\long\def\sort##1##2{\setbox2=\hbox{##2}\setbox
\avmboxthree=\hbox{\avmjsortfont##1\/}\dimen2=\ht2
\advance\dimen2 by -.25\baselineskip
\ifavmtopleft \raise\dimen2\box\avmboxthree\box2%
\else\ifavmtopright \box2\raise\dimen2\box\avmboxthree%
\else\ifavmbottomright \box2\lower\dimen2\box\avmboxthree%
\else \lower\dimen2\box\avmboxthree\box2%
\fi\fi\fi}%
\long\def\osort##1##2{\setbox2=\hbox{##2}\setbox
\avmboxthree=\hbox{\avmjsortfont ##1\/}\avmjsort}%
\def\avml{\avmjprolog.}%
\def\avmr{\avmjpostlog.}%
\def\avmb##1{\node{##1}{\lbrack\;\rbrack}}%
\def\avmd##1{\node{##1}{---}}%
\def\q##1{\ifx ##1\{$\lbrace$\else
\ifx ##1\}$\rbrace$\else
\ifx ##1<$\langle$\else
\ifx ##1>$\rangle$\fi \fi \fi \fi}%
\def\{{\avmjprolog\lbrace}%
\def\}{\avmjpostlog\rbrace}%
\def\;{\hskip\avmjhskip}%
\def\avmspan##1{\multispan2\strut ##1\expandafter\hfil}%
\avmjfont
\openup\avmjvskip
\setbox\avmboxone=\hbox\bgroup\ignorespaces
} % end defn of \avm
\def\endavm{\egroup\ifvmode\leavevmode\fi % this if is useful!
\ifavmsorted\null\hskip\dimen\avmdimen\fi
\ifavmcenter
\box\avmboxone
\else \ifavmbottom
\lower.575\baselineskip\hbox{\vbox{\box\avmboxone\null}}%
\else
% the next bit is ripped off from Emma's \evnup in lingmacros.sty
\dimen2=\ht\avmboxone\advance\dimen2 by -.725\baselineskip
\lower\dimen2\box\avmboxone
\fi \fi \endgroup}
% based on TeXbook exercise 21.3
\def\avmbox#1{\setbox2=\hbox{$\scriptstyle #1$}\lower.2ex\vbox{\hrule
\hbox{\vrule\kern1.25pt
\vbox{\kern1.25pt\box2\kern1.25pt}\kern1.25pt\vrule}\hrule}}
% ============ COSTOM CONFIGURATION =============
\avmfont{\sc}
\avmoptions{sorted,active}
\avmvalfont{\rm}
\avmsortfont{\scriptsize\it}
% ===============================================

View File

@ -0,0 +1,131 @@
%% Last Modified: Thu Oct 18 18:26:25 2007.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{style/btree}
\typeout{Document Style `weiw_BTree - Support drawing B+-Tree (ver 0.999)}
\RequirePackage{tikz}
\RequirePackage{ifthen}
% use libraries
\usetikzlibrary{arrows,shapes,decorations,matrix}
%% global declaration
\tikzstyle{btreeptr} = [draw, semithick, minimum height=2em]
\tikzstyle{btreeval} = [draw, semithick, minimum size=2em]
\tikzstyle{btreevale} = [draw,semithick, minimum size=2em]
\tikzstyle{btlink} = [draw, semithick, ->, >=triangle 45]
%% macro
%% helper macros
\newcommand{\suppressemptystr}[1]{% leave blank for entries in leaf nodes
\ifthenelse{\equal{#1}{}}%
{%
\relax%
}%
% Else
{%
#1\textsuperscript{*}%
}%
}%
\newcommand{\xyshift}[3]{% help to place the nodes
\begin{scope}[xshift=#1, yshift=#2]
#3
\end{scope}%
}
%% Common btree macros
\newcommand{\btreelink}[2]{% #1: src node; #2: dest node;
\draw[btlink] ([yshift=3pt] #1.south) -- (#2-b.north);
}
\newcommand{\btreelinknorth}[2]{% #1: src node; #2: dest node;
\draw[btlink] ([yshift=3pt] #1.south) -- (#2.north);
}
\newcommand{\btreetriangle}[2]{% #1: node name; #2 text inside
\node[anchor=north, regular polygon, regular polygon sides=3, draw] (#1) {#2};
}
%%======================================================================
%% btree with capacity = 4
\newcommand{\btreeinodefour}[5]{%
\matrix [ampersand replacement=\&] (#1)
{
\node[btreeptr] (#1-1) {\vphantom{1}}; \& \node[btreeval] (#1-a) {#2}; \&
\node[btreeptr] (#1-2) {\vphantom{1}}; \& \node[btreeval] (#1-b) {#3}; \&
\node[btreeptr] (#1-3) {\vphantom{1}}; \& \node[btreeval] (#1-c) {#4}; \&
\node[btreeptr] (#1-4) {\vphantom{1}}; \& \node[btreeval] (#1-d) {#5}; \&
\node[btreeptr] (#1-5) {\vphantom{1}}; \\
};
}
\newcommand{\btreelnodefour}[5]{%
\matrix [ampersand replacement=\&, outer sep=0pt, matrix anchor=north] (#1)
{
\node[btreevale] (#1-a) {\suppressemptystr{#2}}; \&
\node[btreevale] (#1-b) {\suppressemptystr{#3}}; \&
\node[btreevale] (#1-c) {\suppressemptystr{#4}}; \&
\node[btreevale] (#1-d) {\suppressemptystr{#5}}; \\
};
}
%%======================================================================
%% btree with capacity = 3
\newcommand{\btreeinodethree}[4]{%
\matrix [ampersand replacement=\&] (#1)
{
\node[btreeptr] (#1-1) {\vphantom{1}}; \& \node[btreeval] (#1-a) {#2}; \&
\node[btreeptr] (#1-2) {\vphantom{1}}; \& \node[btreeval] (#1-b) {#3}; \&
\node[btreeptr] (#1-3) {\vphantom{1}}; \& \node[btreeval] (#1-c) {#4}; \&
\node[btreeptr] (#1-4) {\vphantom{1}}; \\
};
}
\newcommand{\btreelnodethree}[4]{%
\matrix [ampersand replacement=\&, outer sep=0pt, matrix anchor=north] (#1)
{
\node[btreevale] (#1-a) {\suppressemptystr{#2}}; \&
\node[btreevale] (#1-b) {\suppressemptystr{#3}}; \&
\node[btreevale] (#1-c) {\suppressemptystr{#4}}; \\
};
}
%%======================================================================
%% btree with capacity = 2
\newcommand{\btreeinodetwo}[4]{%
\matrix [ampersand replacement=\&] (#1)
{
\node[btreeptr] (#1-1) {\vphantom{1}}; \& \node[btreeval] (#1-a) {#2}; \&
\node[btreeptr] (#1-2) {\vphantom{1}}; \& \node[btreeval] (#1-b) {#3}; \&
\node[btreeptr] (#1-3) {\vphantom{1}}; \\
};
}
\newcommand{\btreelnodetwo}[3]{%
\matrix [ampersand replacement=\&, outer sep=0pt, matrix anchor=north] (#1)
{
\node[btreevale] (#1-a) {\suppressemptystr{#2}}; \&
\node[btreevale] (#1-b) {\suppressemptystr{#3}}; \\
};
}
%%======================================================================
%% simple example
% \begin{center}
% \scalebox{0.7}{
% \begin{tikzpicture}
% %
% \btreeinodefour{root}{13}{17}{24}{30};
% \xyshift{-40mm}{-20mm}{\btreelnodefour{n1}{2}{3}{5}{7}}
% \xyshift{-0mm}{-20mm}{\btreelnodefour{n2}{14}{16}{}{}}
% \xyshift{40mm}{-20mm}{\btreelnodefour{n3}{19}{20}{22}{}}
% \xyshift{80mm}{-20mm}{\btreelnodefour{n4}{24}{27}{29}{}}
% \xyshift{120mm}{-20mm}{\btreelnodefour{n5}{33}{34}{38}{39}}
% %
% \foreach \x in {1,2,...,5} { \btreelink{root-\x}{n\x} }
% \end{tikzpicture}
% }
% \end{center}

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

@ -0,0 +1,38 @@
% Source: ss17_wissschreib (Eva)
\lstset{
basicstyle=\ttfamily\scriptsize\mdseries,
keywordstyle=\bfseries\color[rgb]{0.171875, 0.242188, 0.3125},
identifierstyle=,
commentstyle=\color[rgb]{0.257813, 0.15625, 0},
stringstyle=\itshape\color[rgb]{0.0195313, 0.195313, 0.0117188},
numbers=left,
numberstyle=\tiny,
stepnumber=1,
breaklines=true,
frame=none,
showstringspaces=false,
tabsize=4,
backgroundcolor=\color[rgb]{0.98,0.98,0.98},
captionpos=b,
float=htbp,
language=Python,
xleftmargin=15pt,
xrightmargin=15pt
}
%(deutsche) Sonderzeichen
\lstset{literate=%
{Ä}{{\"A}}1
{Ö}{{\"O}}1
{Ü}{{\"U}}1
{ä}{{\"a}}1
{ö}{{\"o}}1
{ü}{{\"u}}1
{ß}{{\ss}}1
}
%Verwendung im Text:
%-> \begin{lstlisting}[language=Python,firstnumber=27] ... \end{lstlisting}
%-> \begin{lstlisting}[language=Python,numbers=none] ... \end{lstlisting}
%-> \lstinline[language=JAVA]{...}