Java
/**A method for creating a REST endpoint for geospatial school querying
* @param input to center search
* @param radius distance (miles) to go around zipCode
* @return List<School> containing all found schools
*/
@CrossOrigin(origins = "http://localhost:8080")
@GetMapping("/findSchools")
public @ResponseBody
List<School> findSchoolsByAreaAroundZipCode(@RequestParam String input,
@RequestParam double radius) {
try {
Location queriedLoc;
try {
Integer.parseInt(input);
queriedLoc = locationRepository.findByZipCode(input);
} catch (Exception NumberFormatException) {
queriedLoc = locationRepository.findFirstByCity(input.toUpperCase());
}
if (queriedLoc.getZipCode() == null) {
System.out.println("findSchoolsByAreaAroundZipCode Location not found");
return null;
}
GeoJsonPoint queriedPoint = queriedLoc.getLatlon();
List<Location> locations = locationRepository.findByLatlonNear(queriedPoint.getX(),
queriedPoint.getY(), radius*1609.34);
List<School> schools = new ArrayList<>();
for (Location location : locations) {
schools.addAll(location.getSchools());
}
return schools;
} catch (Exception e) {
System.out.println("findSchoolsByAreaAroundZipCode " + e.toString());
return null;
}
}
/**Trey Rhodes
* Parallel Linear Search. Program #5
*/
public class ParallelLinearSearch {
public static void main(String args[]) throws InterruptedException {
int[] n = { /* 1000 numbers */ };
//set a target
int target = /* a target to search for */;
//create 4 threads to search 4 subsections of the array
SearchingThread n1 = new SearchingThread(n, 0, 250, target);
SearchingThread n2 = new SearchingThread(n, 250, 500, target);
SearchingThread n3 = new SearchingThread(n, 500, 750, target);
SearchingThread n4 = new SearchingThread(n, 750, 1000, target);
//start each thread
n1.start(); n2.start(); n3.start(); n4.start();
//join to make sure all threads complete
n1.join(); n2.join(); n3.join(); n4.join();
//find first found occurrence and print it
if (n1.isFound())
System.out.println(n1.getInd());
else if (n2.isFound())
System.out.println(n2.getInd());
else if (n3.isFound())
System.out.println(n3.getInd());
else if (n4.isFound())
System.out.println(n4.getInd());
else
System.out.println("-1");
}
}
public class SearchingThread extends Thread {
int beginInd;
int endInd;
int target;
int[] nums;
int foundInd;
boolean found;
SearchingThread(int[] nums, int beginInd, int endInd, int target) {
this.beginInd = beginInd;
this.endInd = endInd;
this.nums = nums;
this.target = target;
found = false;
}
private void search() {
for (int i = beginInd; i < endInd && !found; i++) {
if (nums[i] == target) {
found = true;
foundInd = i;
}
}
}
public void run() {
search();
}
public int getInd() {
return foundInd;
}
public boolean isFound () {
return found;
}
}
C
/*Trey Rhodes
/ Dynamic Memory Management
/ Algorithms and Data Structures
*/
#include <stdio.h>
#include <stdlib.h>
int nodesDQ = 0;
struct node {
char * word;
struct node * next;
};
int enqueue (char * string, struct node ** head, struct node ** tail) {
struct node * temp = (struct node *) malloc (sizeof(struct node));
if (temp == NULL) {
return 0;
}
(*temp).word = string;
(*temp).next = NULL;
if ((*head) == NULL){
*head = temp;
} else {
(*temp).next = NULL;
(**tail).next = temp;
}
*tail = temp;
return 1;
}
char * dequeue (struct node ** head, struct node ** tail) {
struct node * temp;
char * string = NULL;
if ((*head) != NULL) {
temp = *head;
string = (**head).word;
if ((**head).next == NULL) {
(*tail) = NULL;
}
(*head) = (*temp).next;
free((*temp).word);
free(temp);
}
nodesDQ++;
return string;
}
void main(int argv, char **argc) {
srand(time(NULL));
struct node ** head = (struct node **) malloc (sizeof(struct node));
struct node ** tail = (struct node **) malloc (sizeof(struct node));
int i;
int j;
for (i = 0; i < 10; i++) {
char * sp = (char *)malloc(1000000*sizeof(char));
for (j = 0; j < 1000000; j++) {
(sp) [j] = rand() % 26 + 65;
}
(sp)[999999] = '\0';
enqueue(sp, head, tail);
//printf("%d\n", nodesDQ); fflush(stdout);
}
for (i = 0; i < 100000; i++) {
char * sp = (char *)malloc(1000000*sizeof(char));
for (j = 0; j < 1000000; j++) {
(sp) [j] = rand() % 26 + 65;
}
(sp)[999999] = '\0';
enqueue(sp, head, tail);
dequeue(head, tail);
//printf("%d\n", nodesDQ); fflush(stdout);
}
for (i = 0; i < 12; i++) {
dequeue(head, tail);
//printf("%d\n", nodesDQ); fflush(stdout);
}
printf("%d\n", nodesDQ);
}
/*Trey Rhodes
/ Prims Algorithm
/ Algorithms and Data Structures
*/
#include <stdio.h>
#include <stdlib.h>
/*takes a hardcoded adjacency matrix and computes the shortest path between nodes*/
void main(int argc, char **argv[]) {
/*This 2d array that holds the distances between nodes (0 meaning no possible path)*/
int adjMat[4][4] = {
{ 0, 8, 1, 0 },
{ 8, 0, 6, 3 },
{ 1, 6, 0, 2 },
{ 0, 3 ,2 ,0 }};
/*nodes holds the names of the nodes in the adjacency matrix, left to right and top to
bottom, respectively*/
char nodes[] = { 'A', 'B', 'C', 'D'};
/*prevNodes holds the names of the nodes previous to other nodes*/
char prevNodes[4];
/*curDis holds the current best distances between nodes*/
int curDis[] = { 0, INT_MAX, INT_MAX, INT_MAX };
/*curVis holds 1 for true or 0 for false to see if a node has been visited*/
int curVis[] = { 1, 0, 0, 0 };
/*i is the variable used to iterate through rows in adjMat, j goes through columns*/
int i;
int j;
/*lowest holds the value of the shortest distance, lowestIndx/y hold that values index*/
int lowest = 0;
int lowestInd = 0;
int nextNode = 0;
/*size holds the length of one row in adjMat*/
/*sizeof returns the arithmetic width of the passed parameter ((4*5)/4 = 5)*/
int size = sizeof(adjMat[0]) / sizeof(int);
while(i<4) {
for (j = 0; j < size; j++) {
/*this if statement checks the current best distance of a node against the new distance*/
if (adjMat[nextNode][j] > 0 && adjMat[nextNode][j] < curDis[j] && curVis[j] == 0) {
curDis[j] = adjMat[nextNode][j];
prevNodes[j] = nodes[nextNode];
}
}
lowest = INT_MAX;
lowestInd = INT_MAX;
for (j = 0; j < size; j++) {
if (adjMat[nextNode][j] < lowest && curVis[j] == 0 && adjMat[nextNode][j] > 0) {
lowest = adjMat[nextNode][j];
lowestInd = j;
}
}
if (lowestInd < size) {
curVis[lowestInd] = 1;
nextNode = lowestInd;
}
i++;
}
for (i = 0; i < size; i++) {
if (prevNodes[i] >= 'A')
printf("%c %d %c\n", nodes[i], curDis[i], prevNodes[i]);
else
printf("%c %d\n", nodes[i], curDis[i]);
}
}
JavaScript
(This website!)
//Methods for retrieving data from REST endpoints
methods: {
getSchools() {
this.$axios
.get('http://localhost:8081/schools')
.then(resp => {
this.data = resp.data;
})
.catch(err => {
console.error(err);
});
},
searchSchools() {
const url = 'http://localhost:8081/findSchools';
if (this.search === '') {
this.$axios
.get('http://localhost:8081/schools')
.then(resp => {
this.data = resp.data;
})
.catch(err => {
console.error(err);
});
} else {
this.$axios
.get(url + '?input=' + this.search + '&radius=' + this.radius)
.then(resp => {
this.data = resp.data;
})
.catch(err => {
console.error(err);
});
}
this.search = '';
}
}