Skip to content

Commit

Permalink
1.5.0
Browse files Browse the repository at this point in the history
- performance tweaks
- tooltip updates
- github source control
- code cleanup
- minor bug tweaks and fixes

1.5.0

a
  • Loading branch information
mudzereli committed Oct 21, 2014
1 parent 951041a commit cc73afb
Show file tree
Hide file tree
Showing 61 changed files with 4,825 additions and 0 deletions.
161 changes: 161 additions & 0 deletions AlphanumComparator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* The Alphanum Algorithm is an improved sorting algorithm for strings
* containing numbers. Instead of sorting numbers in ASCII order like
* a standard sort, this algorithm sorts numbers in numeric order.
*
* The Alphanum Algorithm is discussed at http://www.DaveKoelle.com
*
* Based on the Java implementation of Dave Koelle's Alphanum algorithm.
* Contributed by Jonathan Ruckwood <[email protected]>
*
* Adapted by Dominik Hurnaus <[email protected]> to
* - correctly sort words where one word starts with another word
* - have slightly better performance
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
using System;
using System.Collections;
using System.Text;

/*
* Please compare against the latest Java version at http://www.DaveKoelle.com
* to see the most recent modifications
*/
namespace mudsort
{
public class AlphanumComparator : IComparer
{
private enum ChunkType { Alphanumeric, Numeric };
private bool InChunk(char ch, char otherCh)
{
ChunkType type = ChunkType.Alphanumeric;

if (char.IsDigit(otherCh))
{
type = ChunkType.Numeric;
}

if ((type == ChunkType.Alphanumeric && char.IsDigit(ch))
|| (type == ChunkType.Numeric && !char.IsDigit(ch)))
{
return false;
}

return true;
}

public int Compare(object x, object y)
{
String s1 = x as string;
String s2 = y as string;
if (s1 == null || s2 == null)
{
return 0;
}

int thisMarker = 0, thisNumericChunk = 0;
int thatMarker = 0, thatNumericChunk = 0;

while ((thisMarker < s1.Length) || (thatMarker < s2.Length))
{
if (thisMarker >= s1.Length)
{
return -1;
}
else if (thatMarker >= s2.Length)
{
return 1;
}
char thisCh = s1[thisMarker];
char thatCh = s2[thatMarker];

StringBuilder thisChunk = new StringBuilder();
StringBuilder thatChunk = new StringBuilder();

while ((thisMarker < s1.Length) && (thisChunk.Length == 0 || InChunk(thisCh, thisChunk[0])))
{
thisChunk.Append(thisCh);
thisMarker++;

if (thisMarker < s1.Length)
{
thisCh = s1[thisMarker];
}
}

while ((thatMarker < s2.Length) && (thatChunk.Length == 0 || InChunk(thatCh, thatChunk[0])))
{
thatChunk.Append(thatCh);
thatMarker++;

if (thatMarker < s2.Length)
{
thatCh = s2[thatMarker];
}
}

int result = 0;
// If both chunks contain numeric characters, sort them numerically
if (char.IsDigit(thisChunk[0]) && char.IsDigit(thatChunk[0]))
{
thisNumericChunk = Convert.ToInt32(thisChunk.ToString());
thatNumericChunk = Convert.ToInt32(thatChunk.ToString());

if (thisNumericChunk < thatNumericChunk)
{
result = -1;
}

if (thisNumericChunk > thatNumericChunk)
{
result = 1;
}
}
else
{
result = thisChunk.ToString().CompareTo(thatChunk.ToString());
}

if (result != 0)
{
return result;
}
}

return 0;
}
}
}



















25 changes: 25 additions & 0 deletions Globals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

using Decal.Adapter;
using Decal.Adapter.Wrappers;

namespace mudsort
{
public static class Globals
{
public static void Init(string pluginName, PluginHost host, CoreManager core)
{
PluginName = pluginName;

Host = host;

Core = core;
}

public static string PluginName { get; private set; }

public static PluginHost Host { get; private set; }

public static CoreManager Core { get; private set; }
}
}
Loading

0 comments on commit cc73afb

Please sign in to comment.