Shawn Smith

Ranch Hand
+ Follow
since Feb 22, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Shawn Smith

All,

Can anybody provide advice on how to use the JAAS LoginContext to do an authentication against multiple KDC/Realm combination. In other words, if attempt 1 fails against realm A, try realm B.

Something like the pseudo-code below.

As always, any help is greatly appreciated.

12 years ago

Jayesh A Lalwani wrote:How long does split take?



I can measure it, but is should be constant across both tests.
13 years ago

Jayesh A Lalwani wrote:Did you use a HashMap or a HashSet? Just askin

Another thing to consider when evaluating HashSet is the number of collisions in your strings that need to be searched. For a truly random set, the search time on a HashSet should be O(1). However, if all of your input data collides (very unlikely), the performance can degrade to O(n)



HashSet, that HashMap was a typo.
13 years ago

There is a very small subset, and once the data is loaded I do simple iteration:



Sorry, I should have pre-read. There is a very small code set.
13 years ago
I can certainly add the sort to the timing, though that's only going to affect the first iteration.

Essentially this is a dirty word checker. There are 622 dirty words and I ran the entire content of my /usr/share/dict/words file against them (479830) words.

There is a very small subset, and once the data is loaded I do simple iteration:

The test code looks like:


and the passesDirtyWord looks like:



With the commented areas being the difference between the HashSet and the ArrayList.

Please forgive the swear word, it is a dirty word checker after all...

All other code in the test is just loading collections of String's from files.

I'm not sure if this information helps the analysis, but...
13 years ago
So, as a follow up for those keeping score at home:

using



Total time for the for loop: 600 msec

Switching toand using contains took 552 msec

doubling the toSearchFor (actually just running the list more than once) resulted in:
binarySearch
2x - 913 msec (+313)
3x - 1245 msec (+332)
4x - 1626 msec (+381)

HashSet.contains
2x - 874 msec (+322)
3x - 1350 msec (+476)
4x - 1757 msec (+407)

And just to make it interesting, I threw in some c++ standard library (i.e. )
These timings aren't accumulative, just the loop time for each iteration.
1x - 264 msec
2x - 265 msec
3x - 267 msec
etc...

So my conclusions were (and feel free to throw rocks), there's really not a enough of a significant difference in the timed tests between HashSet and binarySearch for something as simple as determining String containment.
13 years ago
I go home for a good nights rest and come back to a wealth of information. Thanks to all for the feedback.

Cheers,
Shawn
13 years ago
Those only return the potential insertion point for a new object. They don't tell you whether an object exists in the collection. I can use that to "look left and right", but I'm really just looking for a true or false.
13 years ago
I basically just need to know if something's in a list and want to avoid full iteration. I've been aGooglin' and so far no luck.

I'll start writing my own in anticipation of the answer....

Cheers,
Shawn
13 years ago

Jeff Verdegan wrote:Note also that for POSIX character classes, Java uses \p{class}, not [:class:], which is spelled out in the docs for java.util.regex.Pattern. Always worth reading before posting to a forum.



Thanks much. I actually had read it and just figured out that Properties was stealing my escape for the \p{class} which had me chasing my tail.

Thanks again for the feedback.
13 years ago
I'm attempting to determine valid email address formation using regex and failing. I've tested the same regex against the C regcomp and regexex, and boost's c++ regex libraries with consistent (and correct results). The java code fails to match on anything though. Any insight into the differences in processing would be greatly appreciated.

The matching code:



The test code:


I'm expecting [email protected] and [email protected] to match.

Cheers,
Shawn
13 years ago
The Advanced UNIX programming book is actually a book about system calls on UNIX and UNIX like systems. It doesn't teach you about the shell, but how, inside of C or C++ to do the low level calls into the operating system.

As far as a good book on Shell programming, I don't know what's current. I learned with the Kernighan and Pike book, "The UNIX Programming Environment", but that was over 20 years ago. I have quite a few books on the subject, but I mostly use them for reference at this point.

OS X doesn't come with a native compiler installed. You can install XCode (http://developer.apple.com/xcode/) and use it to install make and the gnu development tools.

If you're looking for a thicker read that is a good starter for C++, Stroustrup's new book "Programming Principals and Practice Using C++" is a tomb, but covers a lot of ground from the basics through advanced topics. Once you know the basics, Scott Meyers Effect C++ series and Herb Sutters Exceptional C++ series are some of the best I've read on the topic.

Cheers,
Shawn
13 years ago
The K&R book should be fine if you're a beginner. That book, plus Rochkind's advanced UNIX programming kept me going from my first C class through 10 years of professional C programming (albeit a long long time ago).

Cheers,
Shawn
13 years ago
Is there a reason you have to return an instance variable? If you're trying to preserve how many converters exist and there's really no reason to return a handle to an instance you probably don't need to give an instance back to to the caller. In other words, something like:



Hopefully I'm understanding what you're trying to do.

Cheers,
Shawn
13 years ago
ArrayList's are stored in contiguous memory, which means random access can be done using "pointer arithmetic" therefore has constant time and is very fast. Insertion or Deletion from anywhere but the end, however, requires that the remaining data elements have to be moved and a possible resizing memory allocation may have to occur. Adds/Removes from anywhere but the end are expensive.

LinkedLists are not stored in contiguous memory and just keep a reference to the next an previous nodes. This means that middle inserts/deletes are fast (just reassign the node references), but you can only do linear lookups because you have to traverse (non-contiguous means you can't use math to find the nth element).

LinkedHashMap contains additional data to ensure iteration order. Because that data must be managed, slower inserts/deletes. Because it is managed, faster interation (O(1)).