public int CompareKey(NodeKey keyCompareTo) { int ret = 0; if (this.objType != keyCompareTo.NodeKeyType) { return(-1); // throw new xBaseJException("Node key types do not match"); } if (this.objType == dBaseType.C) { String s = (String)this.objKey; s = RebuildString(s); String t = keyCompareTo.ToString(); t = RebuildString(t); return(s.CompareTo(t)); } if (this.objType == dBaseType.F) { NodeFloat nf = (NodeFloat)this.objKey; NodeFloat nft = (NodeFloat)keyCompareTo.objKey; return(nf.CompareTo(nft)); } Double d = (Double)this.objKey; double d2 = d - keyCompareTo.GetDouble; if (d2 < 0.0) { return(-1); } if (d2 > 0.0) { return(1); } return(ret); }
/// <summary> /// Compare this NodeFloat object against another /// </summary> /// <param name="obj">The NodeFloat object you want to compare</param> /// <returns></returns> public int CompareTo(object obj) { if (obj.GetType() == typeof(NodeFloat)) { NodeFloat nf2 = (NodeFloat)obj; if (bSign == 0x10) { if (nf2.bSign == 0x10) { return(0); } return(nf2.bSign < 0 ? -1 : 1); // nf2 is bigger if its > than 0; } if (nf2.bSign == 0x10) { return(bSign < 0 ? 1 : -1); // nf2 is bigger if its > than 0; } if (bSign < 0) { if (nf2.bSign > 0) { return(-1); } } if (bSign > 0) { if (nf2.bSign < 0) { return(1); } } // assume both the same sign if (this.bSize < nf2.bSize) { return(-1); } if (this.bSize > nf2.bSize) { return(1); } for (int i = 0; i < 10; i++) { if (bValue[i] == nf2.bValue[i]) // they're equal go get next { continue; } if (bValue[i] < 0) { // reverse all logic for bytes whose first nibble is 8 or 9 if ((nf2.bValue[i] < 0) && (nf2.bValue[i] < bValue[i])) // though it's smaller it's bigger { return(-1); } return(1); } if (nf2.bValue[i] < 0) { // reverse all logic for bytes whose first nibble is 8 or 9 return(-1); // if nf2 is negative, we know this.value is not neg so nf2 must be bigger. } if (bValue[i] < nf2.bValue[i]) { return(-1); } if (bValue[i] > nf2.bValue[i]) { return(1); } } } return(0); }
public NodeKey(NodeFloat Key) { this.objKey = Key; objType = dBaseType.F; }