Skip to content

Commit b68aa67

Browse files
1.32
1 parent d7f994a commit b68aa67

32 files changed

+118
-99
lines changed

Applied/GaussEaster.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

Applied/Meeus.h

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
// Meeus.h
22

3-
#include <string>
43
#include "_Utils.h"
54

65
namespace easterday {
76
/**
8-
(ulong A) -> (string B)
9-
Finds date B of the easter day in year A.
7+
(unsigned long A) -> (string B)
8+
Finds date B of the Easter day in year A.
109
Uses Meeus algorithm to find Julian Orthodox
11-
day of easter. Returns day B.
10+
day of Easter. Returns day B.
1211
*/
12+
static string MeeusJulianEaster(ulong year);
13+
/**
14+
(unsigned long A) -> (string B)
15+
Finds date B of the Easter day in year A.
16+
Uses Meeus algorithm to find Gregorian Orthodox
17+
day of Easter. Returns day B.
18+
! WORKS ONLY WITHIN 1901..2099 !
19+
*/
20+
static string MeeusGregorianEaster(ulong year);
21+
1322
static string MeeusJulianEaster(ulong year) {
1423
ulong newYear4 = year % 4,
1524
newYear7 = year % 7,
@@ -20,6 +29,32 @@ namespace easterday {
2029
ulong newMonth = (e / 31),
2130
newDay = ((e % 31) + 1);
2231

23-
return std::to_string(newDay) + " " + monthName[newMonth - 1] + " " + std::to_string(year);
32+
return std::to_string(newDay) + " " + monthCalling[newMonth - 1] + " " + std::to_string(year);
33+
}
34+
35+
static string MeeusGregorianEaster(ulong year) {
36+
if (year < 1900 || year > 2099) {
37+
return "Cannot be found";
38+
}
39+
40+
ulong newYear4 = year % 4,
41+
newYear7 = year % 7,
42+
newYear19 = year % 19;
43+
ulong d = (19 * newYear19 + 15) % 30,
44+
e = (2 * newYear4 + 4 * newYear7 - d + 34) % 7;
45+
e = d + e + 114;
46+
ulong newMonth = (e / 31),
47+
newDay = ((e % 31) + 1);
48+
newDay = newDay + 13;
49+
if (newDay > 31 && newMonth == 3) {
50+
newDay = newDay - 31;
51+
newMonth = newMonth + 1;
52+
}
53+
else if (newDay > 30 && newMonth == 4){
54+
newDay = newDay - 30;
55+
newMonth = newMonth + 1;
56+
}
57+
58+
return std::to_string(newDay) + " " + monthCalling[newMonth - 1] + " " + std::to_string(year);
2459
}
2560
} // namespace applied

Applied/ZellerCongruence.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
#include <string>
44

5-
namespace applied {
5+
namespace daycalling {
66
typedef std::string string;
77
typedef unsigned long ulong;
8+
/**
9+
(unsigned long A, unsigned long B, unsigned long C) -> (string D)
10+
Finds day (calling) D of the date A.B.C (where
11+
A - day, B - month, C - year). Uses Zeller
12+
congruence. Returns day calling D.
13+
*/
814
static string ZellerDayOfDate(ulong day, ulong month, ulong year);
915

1016
static const string callings[7] = {
1117
"Saturday", "Sunday", "Monday", "Tuesday",
1218
"Wednesday", "Thursday", "Friday"};
1319

14-
/**
15-
(ulong A, ulong B, ulong C) -> (string D)
16-
Finds day (calling) D of the date A.B.C (where
17-
A - day, B - month, C - year). Uses Zeller
18-
congruence. Returns day calling D.
19-
*/
2020
static string ZellerDayOfDate(ulong day, ulong month, ulong year) {
2121
if (month == 1) {
2222
month = 13;

Applied/_Utils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Utils.h
2-
// must be included and used in each hashing header file
2+
// must be included and used in Meeus.h header file
33
// for ver 1.32
44

55
#pragma once
@@ -9,8 +9,7 @@
99
namespace easterday {
1010
typedef std::string string;
1111
typedef unsigned long ulong;
12-
13-
static const string monthName[12] = {
12+
static const string monthCalling[12] = {
1413
"January", "February", "March", "April", "May", "June",
1514
"July", "August", "September", "October", "November", "December"};
1615
}

Elementary/NaiveExp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace exponentiation {
66
typedef int64_t int64;
7-
87
/**
98
(double A, int64 B) -> (double C)
109
Finds C of the A**B=C equation. Uses naive iteration.

Elementary/SquaringExp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace exponentiation {
66
typedef int64_t int64;
7-
87
/*
98
(double A, int64 B) -> (double C)
109
Finds C of the A**B=C equation. Uses squaring recursion.

Graph/Graph.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// Graph.h
2+
// Helping class for Graph algorithms.
3+
// Might be removed. If so, use algorihtms directly, without Graph and inherited classes.
4+
// for version 1.32
25

36
#pragma once
47

Graph/MinimumSpanningTree/Kruskal.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ namespace mst {
1515
void Unite(int x, int y);
1616
int Set(int i);
1717
};
18-
18+
19+
/**
20+
(vector<vector<int>> A, int C) -> (vector<vector<int>> D)
21+
Finds minimum spanning tree list D of edges list A.
22+
With total number of vertices C. Uses Kruskal's algorithm.
23+
Returns MST list D.
24+
*/
1925
vector MSTKruskal(vector EdgeList, int NoVertex);
2026

2127
DSU::DSU(int size) {

Graph/MinimumSpanningTree/MST.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// MST.h
2+
// Helping class for Graph algorithms.
3+
// Might be removed. If so, use algorihtms directly, without Graph and inherited classes.
4+
// for version 1.32
25

36
#pragma once
47

Graph/MinimumSpanningTree/Prim.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55

66
namespace mst {
77
#define INF 999999
8-
typedef std::vector<std::vector<int>> vector;
8+
typedef std::vector<std::vector<int>> vector;
9+
/**
10+
(vector<vector<int>> A) -> (vector<vector<int>> B)
11+
Finds minimum spanning tree list B of distances matrix A.
12+
Uses Prim's algorithm. Returns MST list B.
13+
*/
914
vector MSTPrim(vector DistancesMatrix);
1015
int MinKey(int key[], bool visited[], int NoVertex);
1116

Graph/ShortestPath/Dijkstra.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
namespace spg {
77
typedef std::vector<std::vector<int>> vector;
8+
/**
9+
(vector<vector<int>> A) -> (vector<vector<int>> B)
10+
Finds shortest path matrix B of distances matrix A.
11+
Uses Dijsktra algorithm. Returns SP matrix B.
12+
*/
813
vector DijkstraTable(vector DistancesMatrix);
914
int Minkey(int key[], bool visited[], int vertices);
1015

Graph/ShortestPath/FloydWarshall.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
namespace spg {
77
typedef std::vector<std::vector<int>> vector;
8+
/**
9+
(vector<vector<int>> A) -> (vector<vector<int>> B)
10+
Finds shortest path matrix B of distances matrix A.
11+
Uses Floyd-Warshall algorithm. Returns SP matrix B.
12+
*/
813
vector FloydTable(vector DistanceMatrix);
914

1015
vector FloydTable(vector DistancesMatrix) {

Graph/ShortestPath/Johnson.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
namespace spg {
66
#define INF 999999
77
typedef std::vector<std::vector<int>> vector;
8+
/**
9+
(vector<vector<int>> A) -> (vector<vector<int>> B)
10+
Finds shortest path matrix B of distances matrix A.
11+
Uses Johnson algorithm. Returns SP matrix B.
12+
*/
813
vector JohnsonTable(vector DistancesMatrix);
914

1015
vector JohnsonTable(vector DistancesMatrix) {

Graph/ShortestPath/SPG.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// SPG.h
2+
// Helping class for Graph algorithms.
3+
// Might be removed. If so, use algorihtms directly, without Graph and inherited classes.
4+
// for version 1.32
25

36
#pragma once
47

Hashing/_Utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ namespace hashing {
2121
typedef std::bitset<8> bitset8;
2222
typedef std::bitset<32> bitset32;
2323

24+
/**
25+
(T A) -> (string B)
26+
Converts A to hexadecimal contained in string B.
27+
Return string B.
28+
*/
2429
template <typename T>
2530
static string intToHex(T number) {
2631
strstream stream;

Hashing/adler32.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
namespace hashing {
66
static const ulong ADLER32_MOD = 65521;
7-
87
/**
98
(string A) -> (string B)
109
Creates checksum B of string A, using
1110
adler32 hashing function.
1211
Return string B - checksum.
1312
*/
13+
static string adler32(const string data);
14+
1415
static string adler32(const string data) {
1516
ulong length = data.length();
1617
uint32 a = 1, b = 0;

Hashing/fnv.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,24 @@
55
namespace hashing {
66
static const uint32 FNV32_PRIME = 0x01000193;
77
static const uint32 FNV32_OFFSET = 0x811c9dc5;
8-
8+
static const uint64 FNV64_PRIME = 0x00000100000001B3;
9+
static const uint64 FNV64_OFFSET = 0xcbf29ce484222325;
910
/**
1011
(string A) -> (string B)
1112
Creates checksum B of string A, using
1213
fnv132 hashing function.
1314
Return string B - checksum.
1415
*/
15-
string fnv132(const string data) {
16+
static string fnv132(const string data);
17+
/**
18+
(string A) -> (string B)
19+
Creates checksum B of string A, using
20+
fnv164 hashing function.
21+
Return string B - checksum.
22+
*/
23+
static string fnv164(const string data);
24+
25+
static string fnv132(const string data) {
1626
ulong length = data.length();
1727
uint32 hash = FNV32_OFFSET;
1828

@@ -24,16 +34,7 @@ namespace hashing {
2434
return intToHex(hash);
2535
}
2636

27-
static const uint64 FNV64_PRIME = 0x00000100000001B3;
28-
static const uint64 FNV64_OFFSET = 0xcbf29ce484222325;
29-
30-
/**
31-
(string A) -> (string B)
32-
Creates checksum B of string A, using
33-
fnv164 hashing function.
34-
Return string B - checksum.
35-
*/
36-
string fnv164(const string data) {
37+
static string fnv164(const string data) {
3738
ulong length = data.length();
3839
uint64 hash = FNV64_OFFSET;
3940

Hashing/sha1.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ namespace hashing {
2929
SHA1 hashing function.
3030
Return string B - hash.
3131
*/
32-
string sha1(const string data);
33-
}
32+
static string sha1(const string data);
33+
} // namespace hashing
3434

3535
namespace hashing {
3636
SHA1::SHA1() {
@@ -164,7 +164,7 @@ namespace hashing {
164164
return res.str();
165165
}
166166

167-
std::string sha1(const std::string data) {
167+
static std::string sha1(const std::string data) {
168168
SHA1 hash;
169169
hash.update(data);
170170
return hash.final();

Hashing/sha2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace hashing {
4545
SHA256 hashing function.
4646
Return string B - hash.
4747
*/
48-
string sha256(const string data);
48+
static string sha256(const string data);
4949
} // namespace hashing
5050

5151
namespace hashing {
@@ -184,7 +184,7 @@ namespace hashing {
184184
return (a & (b | c)) | (b & c);
185185
}
186186

187-
string sha256(const string data) {
187+
static string sha256(const string data) {
188188
SHA256 hash;
189189
hash.update(data);
190190
return hash.final();

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Artemii Saganenko
3+
Copyright (c) 2022-2023 Artemii Saganenko
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@
5656
<br>https://en.wikipedia.org/
5757
## Applied
5858
* <strong>Zeller Congruence</strong> - is an algorithm devised by Christian Zeller in the 19th century to calculate the day of the week for any Julian or Gregorian calendar date. It can be considered to be based on the conversion between Julian day and the calendar date.
59+
* <strong>Meeus</strong> - is an algorithm for calculating the Julian Orthodox Easter day and Gregorian Orthodox Easter day (in between 1901..2099).
5960
<br><br>https://en.wikipedia.org/

TheoryOfNumbers/BorweinPi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace picalc {
66
typedef unsigned short ushort;
7-
87
/*
98
(unsigned short A) -> (double B)
109
Finds pi number B with precision of A.

0 commit comments

Comments
 (0)