First commit for the source code.

Please review the implementation.  The performance is totally
unacceptable it.  We can speed it up with threading or parallel
programming.  Let me know if the logic is at least correct.