Hit.cs and GetFirstProperty()



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Ok, this has been a royal-pain-in-the-ass bug to track down. Bug #
342439. Here's the rundown, after about an hour of meticulously
debugging the complex FindProperty method, I just decided that things
weren't being sorted according to their CompareTo's (which were being
used in the sort). And I realized that our method for determining if the
array was sorted was faulty. So, I present! Le Patch! I left most of my
commented out stuff in there so you could see what was being replaced
etc. Because this is such a major part of the beagle system, I wanna
make sure it works before we do anything, so please, be thorough.

So yeah, AddProperty() used to add the property to the end of the array,
and check if the array was sorted, if it wasn't, then beagle simply
waited until someone was looking for those properties.

The replacement inserts the properties in sorted order as they are
added, which cost's a little more time on the indexing side, but saves
us a sort when querying.

Patch is attached and in bugzilla.

http://bugzilla.gnome.org/show_bug.cgi?id=342439
- --
Cheers,
Kevin Kubasik
240-838-6616
http://kubasik.net/blog
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iQIVAwUBRI63Ov3xZFNDM330AQjnGBAArFc6G8y45I5ytG8SEXyw2vkeqMC0QfzO
84gXvlVKiv5juWieBuiAg8fsrpWl3FRYc7mgSWDa+BJjLfdiowFR22qIFr+LQHys
wdjgJAvmjQpXpm5wuzLI4bmSZxVNU20N1PBFXLE2SkcpcA8F1DDBk5dIIzRxFTqL
So/keiDTV+GpV4Nw+iq6d4foxOMHFmIUe7ubGT2mlH1h9t1MNIIXbJ/yHS5VnrQC
i/iOfhw6hOO5ZBe0Dy0EgiY+YnGVEP32HfrwQVWOuANmIzLoiO3RlcBmy581w7xz
73SMDP0zUgrFhreH5uNqnQXJcz7/05F/2OcSkM4QKeQCvfbx19/HuhE2XqnKX+fm
8OWqWji7wUHZ/GQ3vV4Ay93hwNyTTnRojirQMhAYJpFALAX6B6lc1Pam2n0l+wLJ
5txp4w+YRAtYK8UaR4hh8IKV20YNQFPNDJCmwXFy/IGbDMHdLNubBz/worHoK12f
RzvNCpMdcNnAqaMMOpvbfOilcgJ7WF6yVyTGtatUEhfp3yNagg3QFig6eZ9DsKt0
ZCiPo5Z7xN2Is8bCxsEvqZ6gg+jdSDGgHgV7/BXML4zM2j0omaDoO4SVnRGh4Hl7
BCfgt4hravLOzP5xSeX38W5mARoIjG1Ev7CLMfAGiUhZn/R9MLjj4T/D4DsC+8Ex
NJKxFTFssRo=
=jr//
-----END PGP SIGNATURE-----
Index: ./BeagleClient/Hit.cs
===================================================================
RCS file: /cvs/gnome/beagle/BeagleClient/Hit.cs,v
retrieving revision 1.31
diff -u -1 -2 -r1.31 Hit.cs
--- ./BeagleClient/Hit.cs	5 Apr 2006 18:57:29 -0000	1.31
+++ ./BeagleClient/Hit.cs	13 Jun 2006 12:51:39 -0000
@@ -236,40 +236,56 @@
 		}
 
 		//////////////////////////
 
 		[XmlArray]
 		[XmlArrayItem (ElementName="Property", Type=typeof (Property))]
 		public ArrayList Properties {
 			get {  return properties; }
 		}
 
 		public void AddProperty (Property prop)
 		{
+			//This was a nice idea, but it doesn't work.
+			/*
 			if (sorted && properties.Count > 0) {
 				Property last_prop;
 				last_prop = properties [properties.Count - 1] as Property;
-				if (last_prop.CompareTo (prop) > 0) // i.e. last_prop > prop
+				if (last_prop.CompareTo (prop) > 0) {// i.e. last_prop > prop
+					Console.WriteLine ("In AddProperty: " + last_prop + " to " + prop+ " result: " +last_prop.CompareTo (prop));
 					sorted = false;
+				}
 			}
-
-			properties.Add (prop);
+			*/
+			//FIXME:We should find a smarter way to add these sorted.
+			int position =0;
+			for (int i=0;i<properties.Count; i++){
+				if ( prop.CompareTo (properties[i]) < 0 && i==0)
+					properties.Insert (i,prop);
+				else if (( prop.CompareTo (properties[i]) <= 0) &&
+					(prop.CompareTo (properties[i+1]) >= 0 ))
+					properties.Insert (i,prop);
+				else if ( prop.CompareTo (properties[i]) > 0 && i== properties.Count-1)
+					properties.Add (prop);
+			}
+			//properties.Add (prop);
+			//properties.Sort();
 		}
 
 		private bool FindProperty (string key, out int first, out int top)
 		{
-			if (! sorted) {
-				properties.Sort ();
-				sorted = true;
-			}
+			//if (! sorted) {
+			//	properties.Sort ();
+			//	sorted = true;
+			//}
 			
 			first = 0;
 			top = 0;
 			int range = properties.Count - 1;
 			Property prop;
 
 			// O(log n + |range|)-time algorithm for 1-d range query
 			while (range > 1) {
 				// find middle index
 				int mid = first + (range/2);
 				
 				prop = properties [mid] as Property;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]