Search Results

Search found 3659 results on 147 pages for 'sorted hash'.

Page 124/147 | < Previous Page | 120 121 122 123 124 125 126 127 128 129 130 131  | Next Page >

  • How to Sort a TreeList in Sitecore 6 in the Source

    - by Scott
    My team uses Sitecore 6 as content management system and then .Net to interface with Sitecore API. In many of our templates we make use of a Treelist. When adding a new item to the selected items Treelist it automatically puts the item at the bottom of the list. In some lists they get very large. In most cases end users would like to see these lists sorted descending by a Date field that is part of the templates that can be added as selected to the Treelist. Programmatically on the .Net side its very easy to handle this using Linq OrderByDescending and all displays great in the site to visitors. What I am trying to figure out is how to get it to display the same in Sitecore Content Editor. I've not found anything from Google search other than there seems to be a SortBy you can specify in the source but I tried this and can't get it to have any effect. Has anyone dealt with this before? Again, main goal is to sort items in a Treelist in the Sitecore Content Editor itself. Thanks for any input anyone has.

    Read the article

  • Storing strings from a text file/scanner. Array or built-in?

    - by Flowdorio
    This code snippet is to to read a text file, turn the lines into objects through a different public (non changeable) class(externalClass). The external class does nothing but turn strings (lines from the .txt through nextLine) into objects, and is fully functional. The scanner(scanner3) is assigned to the text file. while (scanner3.hasNext()) { externalClass convertedlines = new externalClass(scanner3.nextLine()); I'm not new to programming, but as I'm new to java, I do not know if this requires me to create an array, or if the returned objects are sorted in some other way. i.e is the "importedlines" getting overwritten with each run of the loop(and I need to introduce an array into the loop), or are the objects stored in some way? The question may seem strange, but with the program I am making it would be harder (but definitely not impossible) if I used an array. Any help would be appreciated. As requested, externalClass: public class exernalClass { private String line; externalClass(String inLine){ line = inLine; } public String giveLine() { return line; } }

    Read the article

  • Loading specific files from arbitrary directories?

    - by Haydn V. Harach
    I want to load foo.txt. foo.txt might exist in the data/bar/ directory, or it might exist in the data/New Folder/ directory. There might be a different foo.txt in both of these directories, in which case I would want to either load one and ignore the other according to some order that I've sorted the directories by (perhaps manually, perhaps by date of creation), or else load them both and combine the results somehow. The latter (combining the results of both/all foo.txt files) is circumstantial and beyond the scope of this question, but something I want to be able to do in the future. I'm using SDL and boost::filesystem. I want to keep my list of dependencies as small as possible, and as cross-platform as possible. I'm guessing that my best bet would be to get a list of every directory (within the data/ folder), sort/filter this list, then when I go to load foo.txt, I search for it in each potential directory? This sounds like it would be very inefficient, if I have dozens of potential directories to search through every time. What's the best way to go about accomplishing this? Bonus: What if I want some of the directories to be archives? ie. considering both data/foo/ and data/bar.zip to both be valid, and pull foobar.txt from either one without caring.

    Read the article

  • Sorting the output from XmlSerializer in C#

    - by prosseek
    In this post, I could get an XML file generated based on C# class. Can I reorder the XML elements based on its element? My code uses var ser = new XmlSerializer(typeof(Module)); ser.Serialize(WriteFileStream, report, ns); WriteFileStream.Close(); to get the XML file, but I need to have the XML file sorted based on a BlocksCovered variable. public class ClassInfo { public string ClassName; public int BlocksCovered; public int BlocksNotCovered; public double CoverageRate; public ClassInfo() {} public ClassInfo(string ClassName, int BlocksCovered, int BlocksNotCovered, double CoverageRate) { this.ClassName = ClassName; this.BlocksCovered = BlocksCovered; this.BlocksNotCovered = BlocksNotCovered; this.CoverageRate = CoverageRate; } } [XmlRoot("Module")] public class Module { [XmlElement("Class")] public List<ClassInfo> ClassInfoList; public int BlocksCovered; public int BlocksNotCovered; public string moduleName; public Module() { ClassInfoList = new List<ClassInfo>(); BlocksCovered = 0; BlocksNotCovered = 0; moduleName = ""; } } Module report = new Module(); ... TextWriter WriteFileStream = new StreamWriter(xmlFileName); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); var ser = new XmlSerializer(typeof(Module)); ser.Serialize(WriteFileStream, report, ns); WriteFileStream.Close();

    Read the article

  • Combine Arbitrary number of polygons together

    - by Jakobud
    I have an arbitrary number of polygons (hexes in this case) that are arranged randomly, but they are all touching another hex. Each individual hex has 6 x,y vertices. The vertex's are known for all the hexes. Can anyone point me in the direction of an algorithm that will combine all the hexes into a single polygon? Essentially I'm just looking for a function that spits out an array of vertex locations that are ordered in a way that when drawing lines from one to the next, it forms the polygon. This is my method so far: Create array of all the vertices for all the hexes. Determine the number of times a vertex occurs in the array If vertex is in the array 3+ times, delete the vertices from the array. If vertex is in the array 2 times, delete one of them. The next step is tricky though. I'm using canvas to draw out these polygons, which essentially involves drawing a line from one vertex to the next. So the order of the vertices in the final array is important. It can't be sorted arbitrarily. Also, I'm not looking for a "convex hull" algorithm, as that would not draw the polygon correctly. Are there any functions out there that do something like this? Am I on the right track or is there a better more efficient way?

    Read the article

  • Is there a Java data structure that is effectively an ArrayList with double indicies and built-in in

    - by Bob Cross
    I am looking for a pre-built Java data structure with the following characteristics: It should look something like an ArrayList but should allow indexing via double-precision rather than integers. Note that this means that it's likely that you'll see indicies that don't line up with the original data points (i.e., asking for the value that corresponds to key "1.5"). As a consequence, the value returned will likely be interpolated. For example, if the key is 1.5, the value returned could be the average of the value at key 1.0 and the value at key 2.0. The keys will be sorted but the values are not ensured to be monotonically increasing. In fact, there's no assurance that the first derivative of the values will be continuous (making it a poor fit for certain types of splines). Freely available code only, please. For clarity, I know how to write such a thing. In fact, we already have an implementation of this and some related data structures in legacy code that I want to replace due to some performance and coding issues. What I'm trying to avoid is spending a lot of time rolling my own solution when there might already be such a thing in the JDK, Apache Commons or another standard library. Frankly, that's exactly the approach that got this legacy code into the situation that it's in right now.... Is there such a thing out there in a freely available library?

    Read the article

  • Top n items in a List ( including duplicates )

    - by Krishnan
    Trying to find an efficient way to obtain the top N items in a very large list, possibly containing duplicates. I first tried sorting & slicing, which works. But this seems unnnecessary. You shouldn't need to sort a very large list if you just want the top 20 members. So I wrote a recursive routine which builds the top-n list. This also works, but is very much slower than the non-recursive one! Question: Which is my second routine (elite2) so much slower than elite, and how do I make it faster ? My code is attached below. Thanks. import scala.collection.SeqView import scala.math.min object X { def elite(s: SeqView[Int, List[Int]], k:Int):List[Int] = { s.sorted.reverse.force.slice(0,min(k,s.size)) } def elite2(s: SeqView[Int, List[Int]], k:Int, s2:List[Int]=Nil):List[Int] = { if( k == 0 || s.size == 0) s2.reverse else { val m = s.max val parts = s.force.partition(_==m) val whole = if( parts._1.size > 1) parts._1.tail:::parts._2 else parts._2 elite2( whole.view, k-1, m::s2 ) } } def main(args:Array[String]) = { val N = 1000000/3 val x = List(N to 1 by -1).flatten.map(x=>List(x,x,x)).flatten.view println(elite2(x,20)) println(elite(x,20)) } }

    Read the article

  • c# How to implement a collection of generics

    - by Amy
    I have a worker class that does stuff with a collection of objects. I need each of those objects to have two properties, one has an unknown type and one has to be a number. I wanted to use an interface so that I could have multiple item classes that allowed for other properties but were forced to have the PropA and PropB that the worker class requires. This is the code I have so far, which seemed to be OK until I tried to use it. A list of MyItem is not allowed to be passed as a list of IItem even though MyItem implements IItem. This is where I got confused. Also, if possible, it would be great if when instantiating the worker class I don't need to pass in the T, instead it would know what T is based on the type of PropA. Can someone help get me sorted out? Thanks! public interface IItem<T> { T PropA { get; set; } decimal PropB { get; set; } } public class MyItem : IItem<string> { public string PropA { get; set; } public decimal PropB { get; set; } } public class WorkerClass<T> { private List<T> _list; public WorkerClass(IEnumerable<IItem<T>> items) { doStuff(items); } public T ReturnAnItem() { return _list[0]; } private void doStuff(IEnumerable<IItem<T>> items) { foreach (IItem<T> item in items) { _list.Add(item.PropA); } } } public void usage() { IEnumerable<MyItem> list= GetItems(); var worker = new WorkerClass<string>(list);//Not Allowed }

    Read the article

  • LINQ Sorting - First three need to be different manufacturers

    - by Rob
    My OM has a 'product' object. Each product has a 'manufacturer id' (property, integer). When I have a list of products to display, the first three are displayed as the 'featured products'. The list is already sorted in a specific sort order, putting the 'featured' products first in the list. However, I now need to ensure the featured products in the listing are from different Manufacturers. I want to have a method to call to do this re-sorting. Trying to utilize LINQ to to the querying of the input 'products' and the 'results' public List<Product> SetFeatures(List<Product> products, int numberOfFeatures) { List<Product> result; // ensure the 2nd product is different manufacturer than the first .... // ensure the 3rd product is a different manufacturer than the first two... // ... etc ... for the numberOfFeatures return result; } Thanks in advance.

    Read the article

  • How do I sort an activerecord result set on a i18n translated column?

    - by PlanetMaster
    Hi, I have the following line in a view: <%= f.select(:province_id, options_from_collection_for_select(Province.find(:all, :conditions => { :country_id => @property.country_id }, :order => "provinces.name ASC"), :id, :name) %> In the province model I have the following: def name I18n.t(super) end Problem is that the :name field is translated (through the province model) and that the ordering is done by activerecord on the english name. The non-english result set can be wrongly sorted this way. We have a province in Belgium called 'Oost-Vlaanderen'. In english that is 'East-Flanders". Not good for sorting:) I need something like this, but it does not work: <%= f.select(:province_id, options_from_collection_for_select(Province.find(:all, :conditions => { :country_id => @property.country_id }, :order => "provinces.I18n.t(name) ASC"), :id, :name) %> What would be the best approach to solve this? As you may have noticed, my coding knowledge is very limited, sorry for that.

    Read the article

  • The best way to structure this database?

    - by James P
    At the moment I'm doing this: gems(id, name, colour, level, effects, source) id is the primary key and is not auto-increment. A typical row of data would look like this: id => 40153 name => Veiled Ametrine colour => Orange level => 80 effects => +12 sp, +10 hit source => Ametrine (Some of you gamers might see what I'm doing here :) ) But I realise this could be sorted a lot better. I have studied database relationships and secondary keys in my A-Level computing class but never got as far as to set one up properly. I just need help with how this database should be organised, like what tables should have what data with what secondary and foreign keys? I was thinking maybe 3 tables: gem, effects, source. Which then have relationships to each other? Can anyone shed some light on this? Is a complex way like I'm proposing really the way to go or should I just carry on with what I'm doing? Cheers.

    Read the article

  • Learning Python else syntax error

    - by user1441016
    Hi I am learning python by doing the practice problems for Open course at MIT 6.00 Intro to Computer Science. I am Trying to do practice problem 1 part 2 create a recursive function to count the instance of key in target. My code so far... from string import * def countSubStringMatchRecursive (target, key,x,s): if (find(target,key)==find(target,key,s)) and (find(target,key)==find(target,key,(find(target,key)))):#if first and last return (1) elif (find(target,key)==find(target,key,s))and (find(target,key)!=find(target,key,(find(target,key)))):#if first but not last x=1 s= find(target,key) return (countSubStringMatchRecursive(target,key,s,x) elif (find(target,key,s))==-1 and (find(target,key)!=find(target,key,s)):#if last but not first return (x+1) elif:(find(target,key,s))!=-1 and (find(target,key)!=find(target,key,s)):#if not last and not first x=x+1 s= find(target,key,s) return (countSubStringMatchRecursive(target,key,s,x) I getting a syntax error at line 8. I would just like to know what I did wrong there. Dont worry about the other mistakes I should be able to get those sorted out. I just Stuck on this. Thanks.

    Read the article

  • Python list recursion type error

    - by Jacob J Callahan
    I can't seem to figure out why the following code is giving me a TypeError: 'type' object is not iterable pastebin: http://pastebin.com/VFZYY4v0 def genList(self): #recursively generates a sorted list of child node values numList = [] if self.leftChild != 'none': numList.extend(self.leftChild.genList()) #error numList.extend(list((self.Value,))) if self.rightChild != 'none': numList.extend(self.rightChild.genList()) #error return numList code that adds child nodes (works correctly) def addChild(self, child): #add a child node. working if child.Value < self.Value: if self.leftChild == 'none': self.leftChild = child child.parent = self else: self.leftChild.addChild(child) elif child.Value > self.Value: if self.rightChild == 'none': self.rightChild = child child.parent = self else: self.rightChild.addChild(child) Any help would be appreciated. Full interpreter session: >>> import BinTreeNode as BTN >>> node1 = BTN.BinaryTreeNode(5) >>> node2 = BTN.BinaryTreeNode(2) >>> node3 = BTN.BinaryTreeNode(12) >>> node3 = BTN.BinaryTreeNode(16) >>> node4 = BTN.BinaryTreeNode(4) >>> node5 = BTN.BinaryTreeNode(13) >>> node1.addChild(node2) >>> node1.addChild(node3) >>> node1.addChild(node4) >>> node1.addChild(node5) >>> node4.genList() <class 'list'> >>> node1.genList() Traceback (most recent call last): File "<interactive input>", line 1, in <module> File "C:...\python\BinTreeNode.py", line 47, in genList numList.extend(self.leftChild.genList()) #error File "C:...\python\BinTreeNode.py", line 52, in genList TypeError: 'type' object is not iterable

    Read the article

  • How to select a single object using Linq in vb.net

    - by Hucker
    I have done a lot of searching to what appears to be a simple LINQ problem but I can't figure out how to do grab an object out of a collection that has a specified minimum (or max value) without resorting to a sort like this: > dim customers= GetCustomers() > > dim youngest = (From c in customers > Order By c.age Ascending).ToList.First This (untested code) structure works fine with the exception that the entire customer array must be sorted and placed into a list for the only purpose of extracting the first value. That can't be the best way to get the minimum! Note that I want the whole c record in this case, not the minumum age of a customer that can be done like this (a typical example): > dim customers= GetCustomers() > > dim youngest = (From c in customers > Select c.age).Min Or even > dim customers= GetCustomers() > > dim youngest = (From c in customers > Select c).Min(Function(x) x.age) I can't for the life of me figure out how to get the whole object (or even the index) without resorting to the sort...

    Read the article

  • How would I sort files to directories based on filenames?

    - by gnomed
    I have a huge number of files to sort all named in some terrible convention. Here are some examples: (4)_mr__mcloughlin____.txt 12__sir_john_farr____.txt (b)mr__chope____.txt dame_elaine_kellett-bowman____.txt dr__blackburn______.txt These names are supposed to be a different person (speaker) each. Someone in another IT department produced these from a ton of XML files using some script but the naming is unfathomably stupid as you can see. I need to sort literally tens of thousands of these files with multiple files of text for each person; each with something stupid making the filename different, be it more underscores or some random number. They need to be sorted by speaker. This would be easier with a script to do most of the work then I could just go back and merge folders that should be under the same name or whatever. There are a number of ways I was thinking about doing this. parse the names from each file and sort them into folders for each unique name. get a list of all the unique names from the filenames, then look through this simplified list of unique names for similar ones and ask me whether they are the same, and once it has determined this it will sort them all accordingly. I plan on using Perl, but I can try a new language if it's worth it. I'm not sure how to go about reading in each filename in a directory one at a time into a string for parsing into an actual name. I'm not completely sure how to parse with regex in perl either, but that might be googleable. For the sorting, I was just gonna use the shell command: `cp filename.txt /example/destination/filename.txt` but just cause that's all I know so it's easiest. I dont even have a pseudocode idea of what im going to do either so if someone knows the best sequence of actions, im all ears. I guess I am looking for a lot of help, I am open to any suggestions. Many many many thanks to anyone who can help. B.

    Read the article

  • What is the n in O(n) when comparing sorting algorithms?

    - by Mumfi
    The question is rather simple, but I just can't find a good enough answer. I've taken a look at the most upvoted question regarding the Big-Oh notation, namely this: Plain English explanation of Big O It says there that: For example, sorting algorithms are typically compared based on comparison operations (comparing two nodes to determine their relative ordering). Now let's consider the simple bubble sort algorithm: for (int i = arr.length - 1; i > 0 ; i--) { for (int j = 0; j<i; j++) { if (arr[j] > arr[j+1]) { switchPlaces(...) } } } I know that worst case is O(n^2) and best case is O(n), but what is n exactly? If we attempt to sort an already sorted algorithm (best case), we would end up doing nothing, so why is it still O(n)? We are looping through 2 for-loops still, so if anything it should be O(n^2). n can't be the number of comparison operations, because we still compare all the elements, right? This confuses me, and I appreciate if someone could help me.

    Read the article

  • Vacancy Tracking Algorithm implementation in C++

    - by Dave
    I'm trying to use the vacancy tracking algorithm to perform transposition of multidimensional arrays in C++. The arrays come as void pointers so I'm using address manipulation to perform the copies. Basically, there is an algorithm that starts with an offset and works its way through the whole 1-d representation of the array like swiss cheese, knocking out other offsets until it gets back to the original one. Then, you have to start at the next, untouched offset and do it again. You repeat until all offsets have been touched. Right now, I'm using a std::set to just fill up all possible offsets (0 up to the multiplicative fold of the dimensions of the array). Then, as I go through the algorithm, I erase from the set. I figure this would be fastest because I need to randomly access offsets in the tree/set and delete them. Then I need to quickly find the next untouched/undeleted offset. First of all, filling up the set is very slow and it seems like there must be a better way. It's individually calling new[] for every insert. So if I have 5 million offsets, there's 5 million news, plus re-balancing the tree constantly which as you know is not fast for a pre-sorted list. Second, deleting is slow as well. Third, assuming 4-byte data types like int and float, I'm using up actually the same amount of memory as the array itself to store this list of untouched offsets. Fourth, determining if there are any untouched offsets and getting one of them is fast -- a good thing. Does anyone have suggestions for any of these issues?

    Read the article

  • How do I deal with different requests that map to the same response?

    - by daxim
    I'm designing a Web service. The request is idempotent, so I chose the GET method. The response is relatively expensive to calculate and not small, so I want to get caching (on the protocol level) right. (Don't worry about memoisation at my part, I have that already covered; my question here is actually also paying attention to the Web as a whole.) There's only one mandatory parameter and a number of optional parameter with default values if missing. For example, the following two map to the same representation of the response. (If this is a dumb way to go about it the interface, propose something better.) GET /service?mandatory_parameter=some_data HTTP/1.1 GET /service?mandatory_parameter=some_data;optional_parameter=default1;another_optional_parameter=default2;yet_another_optional_parameter=default3 HTTP/1.1 However, I imagine clients do not know this and would treat them separate and therefore waste cache storage. What should I do to avoid violating the golden rule of caching? Make up a canonical form, document it (e.g. all parameters are required after all and need to be sorted in a specific order) and return a client error unless the required form is met? Instead of an error, redirect permanently to the canonical form of a request? Or is it enough to not mind how the request looks like, and just respond with the same ETag for same responses?

    Read the article

  • How do I split ONE array to two separate arrays based on magnitude size and a threshold?

    - by youhaveaBigego
    I have an array which has BIG numbers and small numbers in it. I got it from after running a log from WireShark. It is the total number of Bytes of TCP traffic. But Wireshark does not discriminate(it would actually try, and hence it will tell you the traffic stats of ALL types of traffic, but since This is how the Array look like : @Array=qw(10912980 10924534 10913356 10910304 10920426 10900658 10911266 10912088 10928972 10914718 10920770 10897774 10934258 10882186 10874126 8531 8217 3876 8147 8019 68157 3432 3350 3338 3280 3280 7845 7869 3072 3002 2828 8397 1328 1280 1240 1194 1193 1192 1194 6440 1148 1218 4236 1161 1100 1102 1148 1172 6305 1010 5437 3534 4623 4669 3617 4234 959 1121 1121 1075 3122 3076 1020 3030 628 2938 2938 1611 1611 1541 1541 1541 1541 1541 1541 1541 1541 1541 1541 1541 1541 583 370 178) When you look at these this array carefully, one thing is obvious to the human eye. There are really BIG numbers and small numbers. (Basically what I am saying is, there is the 1% class and low income class, no middle class). I want to split the array to two different arrays. That would require me to set a threshold. Array 1 should be ONLY the BIG numbers (10924534-10874126), and array 2 should be the smaller numbers (68157-178). Btw, the array is not sorted. User will NOT input the threshold, and hence should be determined smartly.

    Read the article

  • how to filter text of the selected value in drop down

    - by Carlos
    I have a drop down menu. Has product types. Product types have associated value (from drop down) values correspond to machine groups. So each option should have three variables--Machine name, values, machine group. I can get the Machine name and I can get the machine value (and display them in a different field)...what I have not been able to figure out is how to change the value into the Machine group. jQuery('#MachineName').bind('change', function() { //get selected value from drop down; var selectedValue = jQuery("#MachineName").val(); //populate a text field with the selected drop down value jQuery("#MachineValue").val(selectedValue); What I would like to do is keep that MachineValue but then populate another text field with the sorted MachineGroup I have been trying to run it through something like switch(jQuery(this).val()){ case "236" : newVal = "8"; break; But I don't want to "change" the value I just want to do an "if then" type filter, so maybe something like: '236' => "8", '237' => "5", I just don't know how to properly say "assign the MachineGroup based on the MachineValue" (and then have it populate a different text field) In the end I would have three fields. The drop down, the MachineValue and the MachineGroup. Drop down and value are done, I just need to do Group. (And I can sort Group based on MachineName...just not sure which would be easier)

    Read the article

  • c# counting identical strings from text file

    - by Winkz
    I have a foreach statement where I go through several lines from a text file, where I have trimmed down and sorted out the lines I need. What I want to do is count up on how many times an identical string is present. How do I do this? Here is my code. It's the second if statement where I am stuck: foreach (string line in lines.Where(l => l.Length >= 5)) { string a = line.Remove(0, 11); if ((a.Contains(mobName) && a.Contains("dies"))) { mobDeathCount++; } if (a.Contains(mobName) && a.Contains("drops")) { string lastpart = a.Substring(a.LastIndexOf("drops")); string modifiedLastpart = lastpart.Remove(0, 6); } Heres what some of the lines look like: a bag of coins a siog brandy a bag of coins a bag of coins the Cath Shield a tattered scroll So what im trying to do is counting up there are 3 lines with bag of coins. But i need to make it so that it can be everything, theres a drop lists thats huge. So cant add all of em, would take too long

    Read the article

  • Sort the $_POST variables

    - by Jerry
    Hello guys Might be an easy for you guys. I am trying to sort the $_POST variables that were sent by a form and update the sorted result in mysql. I am not sure how to do it and appreciate it anyone can help me about it. My main.php //I have a loop here. (omitted) //$k will be increased by 1 every time the loop starts, so I will know the total times of the loops //the form will be submitted to update.php echo "<input type='hidden' name='pickTotal' value='".$k."' />"; echo "<input type='hidden' id='point' name='earnedPoint".$k."' value='".$point."' />"; echo "<input type='hidden' id='users' name='userName".$k."' value='".$userPick['user']."' />"; //loop ends My update.php if(isset($_POST['submit'])){ $pickTotal=$_POST['pickTotal']; //get the total loop for ($p=0;$p<=$pickTotal;$p++){ $userToBeUpdated=$_POST['userName'.$p]; $userPoint=$_POST['earnedPoint'.$p]; //sort the $userPoint here. //I need to find out who got the most points //and list user's place. 1st, 2nd, 3rd...etc. //update my mysql } Thanks for any helps.

    Read the article

  • What is the best way to create a running integer id on the AppEngine data storage?

    - by Freed
    For various reasons, I need a unique running integer id for my entities stored on the Google AppEngine. The automatically generated key sort of has this behaviour, but it doesn't start from 1 (or 0) and doesn't guarantee that the generated integer part will come from a continuous sequence. What would be the best way to efficiently implement this on AppEngine? Is there any support from the storage system? To add to the complexity, I might need to do this over entities from different entity groups, meaning I can't just get the highest id right now and save an entity with the next id in a transaction. Might memcache be the way to go..? Edit: I havn't yet implemented this, but to clarify on the memcache idea. I know memcache is unreliable, but in practice it probably won't lose data "too often" to hurt performance. Basically, I would have a memcache entry for the last used id, update it (somehow atomically) whenever I create a new entity and use that id. In the case of memcache not having a value for this entry, I'd get the highest id so far by doing a query on my entities sorted by the id and update memcache (unless someone else had already done so). The only problem I can see with this right now would be atomicity of the operation as a whole if the save of my new entity was also part of a transaction. Thoughts..?

    Read the article

  • Python: Sorting array with custom pattern

    - by Binka
    In my little project here I have sorted a list in decending order, however, my goal is to sort it in this custom pattern. (largest - smallest - next largest - next smallest -)etc. In java I was able to do this like this... My goal is to do the same thing but in python, except backwards. Any ideas on how to convert that last for loop that does the wackysort into python and make it go backwards? public static void wackySort(int[] nums){ //first, this simply sorts the array by ascending order. int sign = 0; int temp = 0; int temp2 = 0; for (int i = 0; i < nums.length; i++){ for (int j = 0; j < nums.length -1; j++){ if (nums[j] > nums[j+1]){ temp = nums[j]; nums[j] = nums[j+1]; nums[j+1] = temp; } } } //prepare for new array to actually do the wacky sort. System.out.println(); int firstPointer = 0; int secondPointer = nums.length -1; int[] newarray = new int[nums.length]; int size = nums.length; //for loop that increments by two taking second slot replacing the last (n-1) term for (int i = 0; i < nums.length -1; i+=2){ newarray[i] = nums[firstPointer++]; newarray[i+1] = nums[secondPointer--]; } //storing those values back in the nums array for (int i = 0; i < nums.length; i++){ nums[i] = newarray[i]; } }

    Read the article

  • How to sort NSMutableArray? Code review needed

    - by JAM
    Good evening. This code works. It sorts an array of cards by both Suit and Card Value. It is also very much brute force. Can you recommend a better way? Does Objective-C help dealing with a situation where object being sorted itself has multiple fields, on which sorting depends? -(void) sort: (NSMutableArray *) deck { NSUInteger count = [deck count]; Card *thisCard; Card *nextCard; int this; int next; BOOL stillSwapping = true; while (stillSwapping) { stillSwapping = false; for (NSUInteger i = 0; i < count; ++i) { this = i; next = i+1; if (next < count) { thisCard = [deck objectAtIndex:this]; nextCard = [deck objectAtIndex:next]; if ([thisCard suit] > [nextCard suit]) { [deck exchangeObjectAtIndex:this withObjectAtIndex:next]; stillSwapping = true; } if ([thisCard suit] == [nextCard suit]) { if ([thisCard value] > [nextCard value]) { [deck exchangeObjectAtIndex:this withObjectAtIndex:next]; stillSwapping = true; } } } } } }

    Read the article

< Previous Page | 120 121 122 123 124 125 126 127 128 129 130 131  | Next Page >