Search Results

Search found 2851 results on 115 pages for 'min'.

Page 23/115 | < Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >

  • Forth: free video tutorials?

    - by Peter Mortensen
    Can you recommend any free Forth video tutorials (except for following) ? The only one I know of is Samuel A. Falvo's excellent "Over The Shoulder Episode 1: Text Preprocessing in Forth". MPEG. 102 MB. There are also videos from the annual Forth Day, but I don't consider those to be tutorials. (Unfortunately Forth is, like R, C, C++, Java, C#, D, COM, .NET, F# and Frontier, an unspecific search term. Search tip for Forth: qualify it with "ans" - as in ANS Forth, the ANSI Forth Standard.) Accumulated based on answers and other information: Introductions to Forth Forth. By Ben Stiglitz. At RubyConf 2008 Orlando Florida, U.S.A. 13 min 35 secs. 32 MB. MP4. Advanced Over The Shoulder Episode 1: Text Preprocessing in Forth. By Samuel A. Falvo. 1 h 06 min 25 secs. 102 MB. MPEG.

    Read the article

  • jump search algorithm

    - by davit-datuashvili
    i am doing jump search algorithm but it show me that element is not in array while it is here is code import java.math.*; public class jamp { public static int min(int a,int b){ return a } public static void main(String[]args){ int a[]=new int[]{3,7,9,12,14,15,16,17,18}; int l=14; System.out.println(jumpsearch(a,a.length,l)); } public static int jumpsearch(int a[],int n, int l ){ int t=0; int b=(int)Math.sqrt(n); while (a[min(b,n)-1]=n) return -1 ; } while (a[t] return -1 ; if ( a[t]==l) { return t; } } return -1; } } please help

    Read the article

  • Why Chrome does not show CSS3 ::-webkit-scrollbar scrollbar for iframe?

    - by Binyamin
    Why Chrome does not show CSS3 ::-webkit-scrollbar scrollbar for iframe? Demo http://jsfiddle.net/laukstein/C9s3P/ <iframe scrolling="yes" style="overflow-x:hidden; overflow-y:scroll; width:150px; height:50px;" src="http://en.wikipedia.org/wiki/Web_browser"></iframe> CSS ::-webkit-scrollbar{ width:0.8em; height:0.8em; background-color:#fff; } ::-webkit-scrollbar:hover{ background-color:#eee; } ::-webkit-resizer{ -webkit-border-radius:4px; background-color:#666; } ::-webkit-scrollbar-thumb{ min-height:0.8em; min-width:0.8em; -webkit-border-radius:4px; background-color: #ddd; } ::-webkit-scrollbar-thumb:hover{ background-color: #bbb; } ::-webkit-scrollbar-thumb:active{ background-color:#888; }

    Read the article

  • Most efficient algorithm for merging sorted IEnumerable<T>

    - by franck
    Hello, I have several huge sorted enumerable sequences that I want to merge. Theses lists are manipulated as IEnumerable but are already sorted. Since input lists are sorted, it should be possible to merge them in one trip, without re-sorting anything. I would like to keep the defered execution behavior. I tried to write a naive algorithm which do that (see below). However, it looks pretty ugly and I'm sure it can be optimized. It may exist a more academical algorithm... IEnumerable<T> MergeOrderedLists<T, TOrder>(IEnumerable<IEnumerable<T>> orderedlists, Func<T, TOrder> orderBy) { var enumerators = orderedlists.ToDictionary(l => l.GetEnumerator(), l => default(T)); IEnumerator<T> tag = null; var firstRun = true; while (true) { var toRemove = new List<IEnumerator<T>>(); var toAdd = new List<KeyValuePair<IEnumerator<T>, T>>(); foreach (var pair in enumerators.Where(pair => firstRun || tag == pair.Key)) { if (pair.Key.MoveNext()) toAdd.Add(pair); else toRemove.Add(pair.Key); } foreach (var enumerator in toRemove) enumerators.Remove(enumerator); foreach (var pair in toAdd) enumerators[pair.Key] = pair.Key.Current; if (enumerators.Count == 0) yield break; var min = enumerators.OrderBy(t => orderBy(t.Value)).FirstOrDefault(); tag = min.Key; yield return min.Value; firstRun = false; } } The method can be used like that: // Person lists are already sorted by age MergeOrderedLists(orderedList, p => p.Age); assuming the following Person class exists somewhere: public class Person { public int Age { get; set; } } Duplicates should be conserved, we don't care about their order in the new sequence. Do you see any obvious optimization I could use?

    Read the article

  • What does the obscure javascript error b(e.target).zIndex is not a function mean?

    - by stormist
    To give more information I am using the modular form here: http://jqueryui.com/demos/dialog/#modal-form b(e.target).zIndex is not a function [Break on this error] (function(a){a.widget("ui.mouse",{opti...is._unrotate}return this}})})(jQuery); /js/jquery-ui.min.js I also seem to be getting the error "Too much recursion" too much recursion [Break on this error] 3||a.nodeType===8)){if(a.setInterval&&...this.special[o]||{};if(!t){t=e[o]={}; https://my.dev.peer1.com/js/jquery/jquery-1.4.min.js I know its not much to go on but I was hoping someone might have experience with similar issues.

    Read the article

  • OSX/Darwin unresolved symbols when linking functions from <math.h>

    - by tbone
    I'm in the process of porting a large'ish (~1M LOC) project from a Window/Visual Studio environment to other platforms, the first of which happens to be Mac OS X. Originally the project was configured as Visual Studio solutions and projects, but now I'm using (the excellent) Premake (http://industriousone.com/premake) to generate project files for multiple platforms (VS, XCode, GMake). I configured, ported and built the first few projects without any significant problems, but having ported the math lib, I ran into this weird linking error that I haven't been able to resolve: Any functions used from math.h will fail to link (causing unresolved symbols). For reference, I'm using Premake v4.2.1 to generate projects for XCode v3.2.1, which is building using gcc v4.2 for the x86_64 architecture. (All this on 64-bit Snow Leopard) I've tried to persuade gcc to link and build everything against a 'known' SDK by adding -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 to the build command line. Now under normal circumstances, adding -lm should take care of this, however in Darwin, those math libs are included in libSystem, which, as far as I can tell, gets implicitly linked by gcc/ld. I've tried creating a dummy project from within XCode which just runs: float f = log2(2.0)+log2f(3.f)+log1p(1.1)+log1pf(1.2f)+sin(8.0); std::cout << f << std::endl; and as expected, this builds just fine. However, if I put the same thing in the code inside the Premake generated project, all those math functions end up unresolved. Now comparing the linking command from the 'native' XCode project with my generated XCode project, they seem pretty identical (except that my generated project links other libs as well). 'Native' project: /Developer/usr/bin/g++-4.2 -arch x86_64 -dynamiclib -isysroot /Developer/SDKs/MacOSX10.6.sdk -Lsomepath -Fsomepath -filelist somefile -install_name somename -mmacosx-version-min=10.6 -single_module -compatibility_version 1 -current_version 1 -o somename Generated project: /Developer/usr/bin/g++-4.2 -arch x86_64 -dynamiclib -Lsomepath -Fsomepath -filelist somefile -install_name somename -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 somelib.a somelib2.a somelib.dylib somelib2.dylib -single_module -compatibility_version 1 -current_version 1 -o somename Any help or hints about how to proceed would be most appreciated. Are there any gcc flags or other tools that can help me resolve this?

    Read the article

  • Clob as param for PL/SQL Java Stored Procedure

    - by JDS
    I have a java stored procedure that takes in a clob representing a chunk of javascript and mins it. The structure of the function calling the JSP is as follows: function MIN_JS(pcl_js in clob) return clob as language java name 'JSMin.min(oracle.sql.CLOB) return oracle.sql.CLOB'; In the actual JSP, I have the following: import oracle.sql.CLOB; public class JSMin { ... public static min(CLOB js) { ... } The problem I'm having is that whenever I pass a clob to JS_MIN, it is always interpreted as null inside the JSP. I've checked the clob before calling JS_MIN annd it definitely has contents. Any ideas as to what I'm missing? Any help is greatly appreciated.

    Read the article

  • How to use a scope in combination with a Model method?

    - by Bjorn
    Hi all, I'm currently working on some scope filters, and I'd like to have it filter on a method (don't know how to name it otherwise). My code: class Product < ActiveRecord::Base def price_with_discount price-discount.to_f end scope :by_price, lambda {|min,max|{ :conditions => { :price_with_discount => min.to_f..max.to_f }}} end This doesn't work: "No attribute named price_with_discount exists for table products". How can I trick my scope into using the method I defined instead of searching for a column named price_with_discount? Bjorn

    Read the article

  • zf2 \Zend\Db\Sql\Sql using predicate in where condition

    - by RomanKonz
    i really don't get the point how to use predicates in zend framework 2. this is what i got: $sql->select() ->columns(array('GroupedColum' ,'minValue' => new Expression('min(ValueColumn)'))) ->from('ValueTable') ->group('GroupedColum') ->order('minValue') ->order('GroupedColum') ->limit(10); this is working fine now i want to apply somethin like that: $predicate = new Zend\Db\Sql\Predicate\Predicate(); $sql->where($predicate->greaterThan('filterColumn','20); this is what i tried, it throws no error, but it is not working :-( This is what i expect as SQL: select GroupedColum , min(ValueColumn) as minValue from ValueTable where filterColumn > 20 group by GroupedColum order by minValue GroupedColum limit 10;

    Read the article

  • CSS text-decoration rule ignored

    - by Ferdy
    I have found similar questions to mine but none of the suggestions seems to apply to my situation, so here goes... I have a webpage with a buch of images on them. Each image has a title which in markup is between h2 tags. The title is a link, so the resulting markup is like this: <ul class="imagelist"> <li> <a href=""><h2>Title 1</h2></a> <a href=""><img src="" /></a> </li> <li> Image 2, etc... </li> </ul> All I want is for the title links to not be underlined. I tried to address this like this: .imagelist li a h2 { color:#333; text-decoration:none; } It completely ignores the text-decoration rule, yet respects the color rule. From other questions I learned that this could be because a child element cannot overrule the text-decoration of any of its parents. So, I went looking for the parent elements to see if any explicit text-decoration rules are applied. I found none. This is driving me crazy, any help? For the sake of completeness, here is the Firebug CSS output, which shows the full inheritance and such. Probably more than you want, but I cannot see anything conflicting here. .imagelist li a h2 { color:#333333; text-decoration:none; } main.css (line 417) h2 { font-size:14px; } main.css (line 40) h1, h2, h3, h4, h5, h6 { display:block; font-weight:bold; margin-bottom:10px; } main.css (line 38) h1, h2, h3, h4, h5, h6 { font-size:100%; font-weight:normal; } reset-min.css (line 7) body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td { margin:0; padding:0; } reset-min.css (line 7) Inherited froma /apps/ju...mage/745 a { color:#0063E2; } main.css (line 55) Inherited fromli .imagelist li { list-style-type:none; } main.css (line 411) li { list-style:none outside none; } reset-min.css (line 7) Inherited fromul.imagelist .imagelist { border-collapse:collapse; font-size:9px; } main.css (line 410) Inherited frombody body, form { color:#333333; font:12px arial,helvetica,clean,sans-serif; } main.css (line 36) Inherited fromhtml html { color:#000000;

    Read the article

  • jQuery - cycle help

    - by MrTunes
    I'm looking to get some help on using the cycle library for jQuery. I'm in the beginner demos, and I got the absolute first one completed. This is the second one on the page. <script src="jquery-1.2.6.min.js" type="text/javascript"></script> <script src="jquery.cycle.all.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $('.pics').cycle({ fx: 'scrollDown', speed: 300, timeout: 2000 }); </script> My CSS is identical to the one on the page, that's why I put .pics in the quotes.

    Read the article

  • Does python have one way of doing things?

    - by gath
    I have always seen in python articles/books that python is simple and it has only one way of doing things. I would like someone to explain to me this concept keeping in mind the example below, if i wanted to get the min and max values of sequence i would do the following; seq=[1,2,3,4,5,6] min(seq) #1 max(seq) #6 but i can also do this; seq[:1] #1 seq[-1] #6 surely this are two ways of doing one simple thing. This confuses me a bit. Gath

    Read the article

  • HTML/CSS set div to height of sibling

    - by Paul
    I have 2 div's contained in a third. One of the contained div's is floated left, the other floated right. I would like the 2 sibling div's to always be at the same height, but am having a problem with this. So far I am only viewing the page in Firefox, and figured I'd worry about any cross-browser issues after I get it working in at least one browser. Here is the markup: <div id="main-container" class="border clearfix"> <div id="left-div" class="border"> ... </div> <div id="right-div" class="border"> ... </div> </div> Here is the CSS: #main-container { position: relative; min-height: 500px; } #left-div { position: relative; float: left; width: 700px; min-height: inherit; } #right-div { position: relative; float: right; width: 248px; min-height: inherit; height: inherit; } .clearfix:after { content: " "; display: block; height: 0; clear: both; visibility: hidden; } .clearfix { display: inline-block; _height: 1%; clear: both; } .clearfix { display: block; clear: both; } .border { border: solid 1px #000; } If the content in the #left-div is longer than 500px, the #right-div does not expand to match. In an example I tried, Firefox said the computed style height of the #main-container was 804px, the computed style height of the #left-div was 800px, and the computed style height of the #right-div was 586.2px, as it had expanded to fit it's own content. I understand I might be going about this the wrong way, and if this is a duplicate questions then I apologize, but I wasn't quite sure what to search under.

    Read the article

  • Symfony 1.4 Layout footer glitch: Footer div is echoed out with $sf_content

    - by Parijat Kalia
    I have a very simple Layout for my application. A header, the main content, and a footer. Semantically, they are rendered like this: <body> <div id = "header"> </div> <div id = "content"> </div> <div id = "footer"> </div> </body> The corresponding CSS is very basic as well: #header{ width:100%; min-height:10%; } #center{ width:100%; min-height:80%; } #footer{ width:100%; min-height:10%: } As you would know in the layout page, here is how the content is rendered: <div id= "content"> <?php echo $sf_content; ?> </div> All of the above is very fine and it renders itself as it is supposed to. But there is a glitch with this, the moment i put in <?php echo $sf_content; ?> the footer is included as part of the content and not as a div that is after the #content markup. Essentially, I get this: <div id = "header"></div> <div id = "content> <div id ="symfony_template_to_be_rendered"> <!-- all web application related content like forms etc. --> </div> <div id = "footer">Footer material </div> </div> As you can see, for some weird reason, the footer moved up along with the symfony content. Clearly this is a glitch because if I remove the php hash $sf_content part from the div tags in my layouts, then the footer renders itself as and where it should be and everything takes up the required dimensions. What's going on here?

    Read the article

  • executing two functions with wshshell

    - by sushant
    i have two different functions (copy and zip) to b executed. can i do it with with a single wshshell script.i tried---- Dim WshShell, oExec,g,h h="D:\d" g="xcopy " & h & " " & "D:\y\ /E & cmd /c cd D:\c & D: & winzip32.exe -min -a D:\a" Set WshShell = CreateObject("WScript.Shell") Set oExec = WshShell.Exec(g) Do While oExec.Status = 0 WScript.Sleep 100 Loop WScript.Echo oExec.Status it dint work.though separate programs i.e g="xcopy " & h & " " & "D:\y\ /E" and g="cmd /c cd D:\d & D: & winzip32.exe -min -a D:\a" works. i am sorry for the formatting problem. any help is appreciated.

    Read the article

  • Concurrent Generation of Sequential Keys

    - by GenTiradentes
    I'm working on a project which generates a very large number of sequential text strings, in a very tight loop. My application makes heavy use of SIMD instruction set extensions like SSE and MMX, in other parts of the program, but the key generator is plain C++. The way my key generator works is I have a keyGenerator class, which holds a single char array that stores the current key. To get the next key, there is a function called "incrementKey," which treats the string as a number, adding one to the string, carrying where necessary. Now, the problem is, the keygen is somewhat of a bottleneck. It's fast, but it would be nice if it were faster. One of the biggest problems is that when I'm generating a set of sequential keys to be processed using my SSE2 code, I have to have the entire set stored in an array, which means I have to sequentially generate and copy 12 strings into an array, one by one, like so: char* keys[12]; for(int i = 0; i < 12; i++) { keys[i] = new char[16]; strcmp(keys[i], keygen++); } So how would you efficiently generate these plaintext strings in order? I need some ideas to help move this along. Concurrency would be nice; as my code is right now, each successive key depends on the previous one, which means that the processor can't start work on the next key until the current one has been completely generated. Here is the code relevant to the key generator: KeyGenerator.h class keyGenerator { public: keyGenerator(unsigned long long location, characterSet* charset) : location(location), charset(charset) { for(int i = 0; i < 16; i++) key[i] = 0; charsetStr = charset->getCharsetStr(); integerToKey(); } ~keyGenerator() { } inline void incrementKey() { register size_t keyLength = strlen(key); for(register char* place = key; place; place++) { if(*place == charset->maxChar) { // Overflow, reset char at place *place = charset->minChar; if(!*(place+1)) { // Carry, no space, insert char *(place+1) = charset->minChar; ++keyLength; break; } else { continue; } } else { // Space available, increment char at place if(*place == charset->charSecEnd[0]) *place = charset->charSecBegin[0]; else if(*place == charset->charSecEnd[1]) *place = charset->charSecBegin[1]; (*place)++; break; } } } inline char* operator++() // Pre-increment { incrementKey(); return key; } inline char* operator++(int) // Post-increment { memcpy(postIncrementRetval, key, 16); incrementKey(); return postIncrementRetval; } void integerToKey() { register unsigned long long num = location; if(!num) { key[0] = charsetStr[0]; } else { num++; while(num) { num--; unsigned int remainder = num % charset->length; num /= charset->length; key[strlen(key)] = charsetStr[remainder]; } } } inline unsigned long long keyToInteger() { // TODO return 0; } inline char* getKey() { return key; } private: unsigned long long location; characterSet* charset; std::string charsetStr; char key[16]; // We need a place to store the key for the post increment operation. char postIncrementRetval[16]; }; CharacterSet.h struct characterSet { characterSet() { } characterSet(unsigned int len, int min, int max, int charsec0, int charsec1, int charsec2, int charsec3) { init(length, min, max, charsec0, charsec1, charsec2, charsec3); } void init(unsigned int len, int min, int max, int charsec0, int charsec1, int charsec2, int charsec3) { length = len; minChar = min; maxChar = max; charSecEnd[0] = charsec0; charSecBegin[0] = charsec1; charSecEnd[1] = charsec2; charSecBegin[1] = charsec3; } std::string getCharsetStr() { std::string retval; for(int chr = minChar; chr != maxChar; chr++) { for(int i = 0; i < 2; i++) if(chr == charSecEnd[i]) chr = charSecBegin[i]; retval += chr; } return retval; } int minChar, maxChar; // charSec = character set section int charSecEnd[2], charSecBegin[2]; unsigned int length; };

    Read the article

  • Kill a 10 minute old zombie process in linux bash script

    - by Steve
    I've been tinkering with a regex answer by yukondude with little success. I'm trying to kill processes that are older than 10 minutes. I already know what the process IDs are. I'm looping over an array every 10 min to see if any lingering procs are around and need to be killed. Anybody have any quick thoughts on this? Thanks, Steve ps -eo uid,pid,etime 3233332 | egrep ' ([0-9]+-)?([0-9]{2}:?){3}' | awk '{print $2}' | xargs -I{} kill {} I've been tinkering with the answer posted by yukondude with little success. I'm trying to kill processes that are older than 10 minutes. I already know what the process IDs are. I'm looping over an array every 10 min to see if any lingering procs are around and need to be killed. Anybody have any quick thoughts on this? Thanks, Steve

    Read the article

  • jQuery UI - Draggable is not a function?

    - by Dan
    Hi, I've trying to use the draggable effect on some divs on a page, but whenever I load the page, I get the error message: Error: $(".draggable").draggable is not a function I've had a look around it seemed other people were having this problem as they had not included the jQuery UI javascript file, but I definitely have. The following is within the head tag of my page: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script> Can anyone suggest a solution? Any advice appreciated. Thanks.

    Read the article

  • MooTools Fx.Slide throwing this.element is null

    - by Brant
    The following code is throwing the error "this.element is null". However, the wid_cont is definitely grabbing an element. window.addEvent('domready',function(){ var min = $(document.body).getElements('a.widget_minimize'); min.addEvent('click', function(event){ event.stop(); //var box = ; var wid_cont = ($(this).getParents('.widget_box').getElement('.widget_box_content_cont')); var myVerticalSlide = new Fx.Slide(wid_cont); myVerticalSlide.slideOut(); } ); }); It's moo tools 1.2.4 and has the fx.slide included....

    Read the article

  • generate unix timestamp from last time

    - by Nazmin
    hi guys, suppose i have one column in mysql database which is stated last time one equipment is up in h:i:s format (ex: 00:05:11) or 1d21h, means that the equipment is on since 5 min before, what is the best method i can convert this to unix timestamp, say if using php script how? or direct convert last unix timestamp using mysql function query. actually, i want to calculate for start time for this equipment uptime in unix timestamp where i have one column in mysql startcapture that will be deducted with last column to get start time. so starttime = startcapture - last (this last time that has to convert to unix timestamp based on now() - h:i:s ). but the problem is sometimes the format change from h:i:s to ex: 1d22h, if h:i:s means the equipment is up since ex: 00:05:11 min before and if 1d22h means the equipment already up 1 day 22 hours before. so the main things here is to convert last column to appropriate unix timestamp. please help guys, asap.

    Read the article

  • Using jQuery UI with Rails

    - by Steve
    Hi, I am using jQuery in my Rails App. But when I try to turn my button to jQueryUI(Cupertino theme) button, it does not appear to be look like a jQuery UI Themed button. jQuery works because I am using it for Ajax and it works properly. I have pasted the code. Please tell me whether I am doing it wrongly <%=javascript_include_tag "jquery-1.4.2.min","jquery-ui-1.8.1.min","jquery.nivo.slider.pack","application"%> <input type = submit id = "add" name = "add" value = " Add " /> $("#add").button(); Thanks

    Read the article

  • Random number generation

    - by Chandan Shetty SP
    I am using below code to generate random numbers in range... int randomNumberWithinRange(int min,int max) { int snowSize = 0; do { snowSize = rand()%max; } while( snowSize < min || snowSize > max ); return snowSize; } for(int i = 0; i < 10 ; i++) NSlog("@"%d",\t", randomNumberWithinRange(1,100)); If I quit my application and restart, same set of numbers are generated. How to generate different set of random numbers for every launching.

    Read the article

  • Linq to Sql Projection Help

    - by Micah
    I've reached the end of my Linq rope. Need your help! Heres my table structure first(all linq to sql objects): InventoryItems -ID -AmtInStock IventoryKits -ID InventoryKits_to_InventoryItems -InventoryItemID -InventoryKitID So i need to do a projection like the following var q2=from k in GetAllKits()//returns IQueryable<InventoryKit> select new VMPublication()//ViewModel Object { ID = k.ID, Name = k.Name, WebAmountInStock = ,//need to get the Min() AmtInStock from InventoryItems here ItemCode = k.ItemCode, WebAmountOrdered = k.AmtOrdered.ToString(), WebReminderAmount = "", WebAmountWarning="", Type = "Kit" }; i have no idea how to get that Min() of InventoryItem's AmtInStock in that query. Please help! Very Appreciated!

    Read the article

  • What statistics can be maintained for a set of numerical data without iterating?

    - by Dan Tao
    Update Just for future reference, I'm going to list all of the statistics that I'm aware of that can be maintained in a rolling collection, recalculated as an O(1) operation on every addition/removal (this is really how I should've worded the question from the beginning): Obvious Count Sum Mean Max* Min* Median** Less Obvious Variance Standard Deviation Skewness Kurtosis Mode*** Weighted Average Weighted Moving Average**** OK, so to put it more accurately: these are not "all" of the statistics I'm aware of. They're just the ones that I can remember off the top of my head right now. *Can be recalculated in O(1) for additions only, or for additions and removals if the collection is sorted (but in this case, insertion is not O(1)). Removals potentially incur an O(n) recalculation for non-sorted collections. **Recalculated in O(1) for a sorted, indexed collection only. ***Requires a fairly complex data structure to recalculate in O(1). ****This can certainly be achieved in O(1) for additions and removals when the weights are assigned in a linearly descending fashion. In other scenarios, I'm not sure. Original Question Say I maintain a collection of numerical data -- let's say, just a bunch of numbers. For this data, there are loads of calculated values that might be of interest; one example would be the sum. To get the sum of all this data, I could... Option 1: Iterate through the collection, adding all the values: double sum = 0.0; for (int i = 0; i < values.Count; i++) sum += values[i]; Option 2: Maintain the sum, eliminating the need to ever iterate over the collection just to find the sum: void Add(double value) { values.Add(value); sum += value; } void Remove(double value) { values.Remove(value); sum -= value; } EDIT: To put this question in more relatable terms, let's compare the two options above to a (sort of) real-world situation: Suppose I start listing numbers out loud and ask you to keep them in your head. I start by saying, "11, 16, 13, 12." If you've just been remembering the numbers themselves and nothing more, and then I say, "What's the sum?", you'd have to think to yourself, "OK, what's 11 + 16 + 13 + 12?" before responding, "52." If, on the other hand, you had been keeping track of the sum yourself while I was listing the numbers (i.e., when I said, "11" you thought "11", when I said "16", you thought, "27," and so on), you could answer "52" right away. Then if I say, "OK, now forget the number 16," if you've been keeping track of the sum inside your head you can simply take 16 away from 52 and know that the new sum is 36, rather than taking 16 off the list and them summing up 11 + 13 + 12. So my question is, what other calculations, other than the obvious ones like sum and average, are like this? SECOND EDIT: As an arbitrary example of a statistic that (I'm almost certain) does require iteration -- and therefore cannot be maintained as simply as a sum or average -- consider if I asked you, "how many numbers in this collection are divisible by the min?" Let's say the numbers are 5, 15, 19, 20, 21, 25, and 30. The min of this set is 5, which divides into 5, 15, 20, 25, and 30 (but not 19 or 21), so the answer is 5. Now if I remove 5 from the collection and ask the same question, the answer is now 2, since only 15 and 30 are divisible by the new min of 15; but, as far as I can tell, you cannot know this without going through the collection again. So I think this gets to the heart of my question: if we can divide kinds of statistics into these categories, those that are maintainable (my own term, maybe there's a more official one somewhere) versus those that require iteration to compute any time a collection is changed, what are all the maintainable ones? What I am asking about is not strictly the same as an online algorithm (though I sincerely thank those of you who introduced me to that concept). An online algorithm can begin its work without having even seen all of the input data; the maintainable statistics I am seeking will certainly have seen all the data, they just don't need to reiterate through it over and over again whenever it changes.

    Read the article

  • Generating a error code per property in Hibernate validator

    - by Mike Q
    Hi all, I am looking at using hibernate validator for a requirement of mine. I want to validate a bean where properties may have multiple validation checks. e.g. class MyValidationBean { @NotNull @Length( min = 5, max = 10 ) private String myProperty; } But if this property fails validation I want a specific error code to be associated with the ConstraintViolation, regardless of whether it failed because of @Required or @Length, although I would like to preserve the error message. class MyValidationBean { @NotNull @Length( min = 5, max = 10 ) @ErrorCode( "1234" ) private String myProperty; } Something like the above would be good but it doesn't have to be structured exactly like that. I can't see a way to do this with hibernate validator. Is it possible? Thanks.

    Read the article

< Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >