Tuesday, September 30, 2014

Changes 9/30/14

Java:

  • Looked at Safari textbook, but only a little
  • Learned more about looking at big O notation for measuring the efficiency of algorithms
  • In my LList program, added support for adding elements to a specific index.  It was actually really simple to implement.  I'll set up Github for Windows tomorrow and upload the source.

Monday, September 29, 2014

Changes 9/29/14

Ruby:

Java:

  • Learned more about big O notation and mapping out the amount of time it takes functions to run.
  • I'm having trouble understanding some of the things they are doing, so I'll have to talk to you tomorrow about it, since I'm out of time today
  • Forgot to look at the safari book, I'll do that tomorrow as well

Friday, September 26, 2014

Changes 9/26/14

Ruby:

  • Looked into ruby's Queue object
  • Saw that the method Queue#pop, which returns the first element and removes it from the queue, is blocking, meaning that it will block its thread if the queue is empty while waiting for a value to return.
  • This is great for me, because I was looking for a way to have a thread that could pause itself while waiting for files to download and resume itself once those files are downloaded
  • I rewrote my threading test to use the queue object, and it ended up being much more straight-forward and probably more thread safe as well

  • In the code marked 1. in the code section I have an excerpt I came up with to utilize Queue#pop.  This code is intended to be run in a method in a separate thread, and will either parse items if there are any in the queue or do nothing while waiting for more to be added
  • END_PARSE_SYM is a constant value that is added to the queue when another method, Parser#finish, is called.  As you can see by the code, this signals that there are no more files for the queue to wait for, and therefore the infinite while loop is exited.

  • One choice I made while writing my Parser class was to keep the thread behavior up to the code calling the Parser#parse method, meaning that Parser doesn't actually have any multithreading code.
  • Instead, you must call something like what is listed in code excerpt 2.  The statement within the { } runs in a separate thread, which is good, because in its current form, this method blocks its thread due to the Queue#pop statement being called on an empty queue within Parser#parse
  • A side effect of this is that if you call parser.parse in the main thread, it throws a deadlock exception, because the @queue.pop statement is now blocking the main thread, so nothing will ever happen.  I think this is acceptable behavior though, because Parser#parse really should never be called in the main thread anyway.
  • I will look into other ways to throw an exception if Parser#parse is being called in the main thread

Code:

1.
def parse
  ...
  while true do
    puts "Waiting for queue" if @queue.empty?
    file = @queue.pop
    break if file == END_PARSE_SYM
    <... parse code here >
  end
end
2.
thread = Thread.new { parser.parse }

Thursday, September 25, 2014

Changes 9/25/14

Java:

  • Worked more on improving the LList class
  • Added a size() variable, so you can get the size of the LList
  • Each time an element is added to the array, the size is increased
  • Currently there is no way to remove elements, so the size can never decrease
  • With this size() variable, the class can also do bounds checking.  For example, with the code LList<String> llist = new LList<String>("sudo", "rm", "-rf");, calling llist.get(5); would result in Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 5 out of bounds for <LList elements=[sudo, rm, -rfl]>
  • As you can see from this example, the LList.toString() method prints out the elements it contains.  This uses a StringBuilder object to avoid the inefficiencies of adding strings together with the + operator (such as "abc" + "def").  Instead, you use the append() method of StringBuilder, then convert the StringBuilder to a string when you want to use it as one.
  • I think that the LList structure is really interesting.  The fact that you can have infinitely sized lists with no penalty for adding or removing elements is really cool, but I can see the drawbacks as well.  For example, if something happens and one Node gets unlinked, all the other Nodes after it will get unlinked as well.
  • Tomorrow I will work on implementing a remove() method for elements, and finish implementing a LList.toArray() method, which will return an array of the data stored in the LList

Tuesday, September 23, 2014

Changes 9/23/14

Java:

  • Continued reading the Data Structures and Abstractions book
  • Renamed my ChainLink class to Nodes like they have in the book, and hid them within a class called LList, so the end user doesn't have to deal with creating and traversing Nodes himself.  Instead, the LList class takes care of it
  • Right now it doesn't actually work, but I'll fix it tomorrow

Monday, September 22, 2014

Changes 9/22/14

Java:

  • Finished up looking at quicksorts
  • Started learning about preconditions, postconditions, and loop invariants, which are assertions you can make within a loop
  • Started learning about timing functions

Friday, September 19, 2014

Changes 9/19/14

Java:

  • Finished up the eimacs hash table section
  • I feel like it wrapped up too quick, it just showed the basics without really talking about advanced hash collision strategies and stuff like that
  • Started looking at sorting algorithms
  • It's walking me through how an in-place quicksort works, which is when an array is sorted just by swapping the placement of elements
  • It's very complicated, but they do a good job of walking you through it slowly
  • They have an interactive example where it highlights the step the program is on, and explains what is being done