Search Results

Search found 4919 results on 197 pages for 'integer'.

Page 5/197 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How to deal with 2 almost identical tables

    - by jgritty
    I have a table of baseball stats, something like this: CREATE TABLE batting_stats( ab INTEGER, pa INTEGER, r INTEGER, h INTEGER, hr INTEGER, rbi INTEGER, playerID INTEGER, FOREIGN KEY(playerID) REFERENCES player(playerID) ); But then I have a table of stats that are basically exactly the same, but for a team: CREATE TABLE team_batting_stats( ab INTEGER, pa INTEGER, r INTEGER, h INTEGER, hr INTEGER, rbi INTEGER, teamID INTEGER, FOREIGN KEY(teamID) REFERENCES team(teamID) ); My first instinct is to scrap the Foreign key and generalize the ID, but I still have a problem, I have these 2 tables, and they can't have overlapping IDs: CREATE TABLE player( playerID INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT, number INTEGER, teamID INTEGER, FOREIGN KEY(teamID) REFERENCES team(teamID) ); CREATE TABLE team( teamID INTEGER PRIMARY KEY, name TEXT, city TEXT, ); I feel like I'm overlooking something obvious that could solve this problem and reduce stats to a single table.

    Read the article

  • How to store a reference to an integer in C#?

    - by Jonathon Reinhart
    Hello everyone - tell me how to make this work? Basically, I need an integer reference type (int* would work in C++) class Bar { private ref int m_ref; // This doesn't exist public A(ref int val) { m_ref = val; } public void AddOne() { m_ref++; } } class Program { static void main() { int foo = 7; Bar b = new Bar(ref foo); b.AddOne(); Console.WriteLine(foo); // This should print '8' } } Do I have to use boxing?

    Read the article

  • php encrypting an integer to get only alphanumeric characters?

    - by Matthew Steiner
    When I use some of php's encryption functions, I end up getting a few characters I don't want (+, /, =). The problem is that my application doesn't allow these in the url. I'm wondering if there's a good way of encrypting an integer and having only alphanumeric characters in the result? I'm trying to pass some data through the url. I know it's possible to do some workarounds (put data in database and pass the id to the row or something), but I really want to try it this way. Ideas?

    Read the article

  • How to find multiples of the same integer in an arraylist?

    - by Dan
    Hi My problem is as follows. I have an arraylist of integers. The arraylist contains 5 ints e.g[5,5,3,3,9] or perhaps [2,2,2,2,7]. Many of the arraylists have duplicate values and i'm unsure how to count how many of each of the values exist. The problem is how to find the duplicate values in the arraylist and count how many of that particular duplicate there are. In the first example [5,5,3,3,9] there are 2 5's and 2 3's. The second example of [2,2,2,2,7] would be only 4 2's. The resulting information i wish to find is if there are any duplicates how many of them there are and what specific integer has been duplicated. I'm not too sure how to do this in java. Any help would be much appreciated. Thanks.

    Read the article

  • Is it possible to cast the Elapsed Time function to Integer?

    - by nuvio
    I have the following function: (def elapsedtime (with-out-str (time (run-my-function)))) and I was wondering if is possible to store only the integer value of the time, as I can only store a String at the moment.... Any suggestion? Thanks a lot UPDATE So I did use this: (defmacro nsecs [expr] `(let [start# (. System (nanoTime))] ~expr (- (. System (nanoTime)) start#))) And then modified this: (def elapsedtime (nsecs (run-my-function argument1 argument2))) but doesn't work, what am I doing wrong? "Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Wrong number of args (1) passed to: main$fn--105$nsecs"

    Read the article

  • How to parse a string to an integer without library functions?

    - by dack
    Hi, I was recently asked this question in an interview: "How could you parse a string of the form '12345' into its integer representation 12345 without using any library functions, and regardless of language?" I thought of two answers, but the interviewer said there was a third. Here are my two solutions: Solution 1: Keep a dictionary which maps '1' = 1, '2' = 2, etc. Then parse the string one character at a time, look up the character in your dictionary, and multiply by place value. Sum the results. Solution 2: Parse the string one character at a time and subtract '0' from each character. This will give you '1' - '0' = 0x1, '2' - '0' = 0x2, etc. Again, multiply by place value and sum the results. Can anyone think of what a third solution might be? Thanks.

    Read the article

  • Java ternary operator and boxing Integer/int?

    - by Markus
    I tripped across a really strange NullPointerException the other day caused by an unexpected type-cast in the ternary operator. Given this (useless exemplary) function: Integer getNumber() { return null; } I was expecting the following two code segments to be exactly identical after compilation: Integer number; if (condition) { number = getNumber(); } else { number = 0; } vs. Integer number = (condition) ? getNumber() : 0; . Turns out, if condition is true, the if-statement works fine, while the ternary opration in the second code segment throws a NullPointerException. It seems as though the ternary operation has decided to type-cast both choices to int before auto-boxing the result back into an Integer!?! In fact, if I explicitly cast the 0 to Integer, the exception goes away. In other words: Integer number = (condition) ? getNumber() : 0; is not the same as: Integer number = (condition) ? getNumber() : (Integer) 0; . So, it seems that there is a byte-code difference between the ternary operator and an equivalent if-else-statement (something I didn't expect). Which raises three questions: Why is there a difference? Is this a bug in the ternary implementation or is there a reason for the type cast? Given there is a difference, is the ternary operation more or less performant than an equivalent if-statement (I know, the difference can't be huge, but still)?

    Read the article

  • Given an integer, determine if it is a Palindrome in less than O(n) [on hold]

    - by user134235
    There is an O(n) solution to the problem of determining if an integer is a palindrome below. Is it possible to solve this problem in O(log n) or better? static void IsPalindrome(int Number) { int OrignalNum = Number; int Reverse = 0; int Remainder = 0; if (Number > 0) { while (Number > 0) { Remainder = Number % 10; Reverse = Reverse * 10 + Remainder; Number = Number / 10; } if (OrignalNum == Reverse) Console.WriteLine("It is a Palindrome"); else Console.WriteLine("It is not a Palindrome"); } else Console.WriteLine("Enter Number Again"); }

    Read the article

  • Using a texture as an integer array (OpenGL 3.3, shader version 3.3)

    - by Cubic
    I'm trying to have something like an integer array uniform for my fragment shader (I only need read access). Since it's a fairly large chunk of data (not so large that uploading it in every frame would be impossible, but enough to make me want to rather not do it). Essentially I want to just pass it a uniform telling the shader where this "array" is. I believe I can use a 1D texture for this, but I don't know how (actually, I don't know how to do many things because I just can't seem to find a reference for GLSL 3.3, I only ever find references for the C API). This sounds like a rather basic question and I'm sure it's been answered already somewhere, but I keep searching and can't quite find what I'm looking for.

    Read the article

  • Searching integer sequences

    - by David Gibson
    I have a fairly complex search problem that I've managed to reduce to the following description. I've been googling but haven't been able to find an algorithm that seems to fit my problem cleanly. In particular the need to skip arbitrary integers. Maybe someone here can point me to something? Take a sequence of integers A, for example (1 2 3 4) Take various sequences of integers and test if any of them match A such that. A contains all of the integers in the tested sequence The ordering of the integers in the tested sequence are the same in A We don't care about any integers in A that are not in the test sequence We want all matching test sequences, not just the first. An example A = (1 2 3 4) B = (1 3) C = (1 3 4) D = (3 1) E = (1 2 5) B matches A C matches A D does not match A as the ordering is different E does not match A as it contains an integer not in A I hope that this explanation is clear enough. The best I've managed to do is to contruct a tree of the test sequences and iterate over A. The need to be able to skip integers leads to a lot of unsuccessful search paths. Thanks Reading some suggestions I feel that I have to clarify a couple of points that I left too vague. Repeated numbers are allowed, in fact this is quite important as it allows a single test sequence to match A is multiple ways A = (1234356), B = (236), matches could be either -23---6 or -2--3-6 I expect there to be a very large number of test sequences, in the thousands at least and sequence A will tend to have a max length of maybe 20. Thus simply trying to match each test sequence one by one by iterating becomes extremely inefficient. Sorry if this wasn't clear.

    Read the article

  • How to define an Integer bean in Struts 1.x

    - by ian_scho_es
    Hi. How do you instantiate an Integer bean, assigning a value, in the Struts 1.x framework? <bean:define id="index" type="java.lang.Integer" value="0"/> or <bean:define id="index" type="java.lang.Integer" value="${0}"/> Results in a: java.lang.ClassCastException: java.lang.String <bean:define id="index" type="java.lang.Integer" value="<%=0%>"/> Results in: The method setValue(String) in the type DefineTag is not applicable for the arguments (int) <% java.lang.Integer index = new java.lang.Integer(0); %> Works, but makes my eyes bleed. Note that I had to refactor iterating over a list but am now applying a filter within the iteration. This was the cleanest solution of all! <logic:equal name="aplicacion" property="generico" value="false" indexId="index"> Maybe I need to go about this completely differently. Many thanks.

    Read the article

  • How to obtain a random sub-datatable from another data table

    - by developerit
    Introduction In this article, I’ll show how to get a random subset of data from a DataTable. This is useful when you already have queries that are filtered correctly but returns all the rows. Analysis I came across this situation when I wanted to display a random tag cloud. I already had the query to get the keywords ordered by number of clicks and I wanted to created a tag cloud. Tags that are the most popular should have more chance to get picked and should be displayed larger than less popular ones. Implementation In this code snippet, there is everything you need. ' Min size, in pixel for the tag Private Const MIN_FONT_SIZE As Integer = 9 ' Max size, in pixel for the tag Private Const MAX_FONT_SIZE As Integer = 14 ' Basic function that retreives Tags from a DataBase Public Shared Function GetTags() As MediasTagsDataTable ' Simple call to the TableAdapter, to get the Tags ordered by number of clicks Dim dt As MediasTagsDataTable = taMediasTags.GetDataValide ' If the query returned no result, return an empty DataTable If dt Is Nothing OrElse dt.Rows.Count < 1 Then Return New MediasTagsDataTable End If ' Set the font-size of the group of data ' We are dividing our results into sub set, according to their number of clicks ' Example: 10 results -> [0,2] will get font size 9, [3,5] will get font size 10, [6,8] wil get 11, ... ' This is the number of elements in one group Dim groupLenth As Integer = CType(Math.Floor(dt.Rows.Count / (MAX_FONT_SIZE - MIN_FONT_SIZE)), Integer) ' Counter of elements in the same group Dim counter As Integer = 0 ' Counter of groups Dim groupCounter As Integer = 0 ' Loop througt the list For Each row As MediasTagsRow In dt ' Set the font-size in a custom column row.c_FontSize = MIN_FONT_SIZE + groupCounter ' Increment the counter counter += 1 ' If the group counter is less than the counter If groupLenth <= counter Then ' Start a new group counter = 0 groupCounter += 1 End If Next ' Return the new DataTable with font-size Return dt End Function ' Function that generate the random sub set Public Shared Function GetRandomSampleTags(ByVal KeyCount As Integer) As MediasTagsDataTable ' Get the data Dim dt As MediasTagsDataTable = GetTags() ' Create a new DataTable that will contains the random set Dim rep As MediasTagsDataTable = New MediasTagsDataTable ' Count the number of row in the new DataTable Dim count As Integer = 0 ' Random number generator Dim rand As New Random() While count < KeyCount Randomize() ' Pick a random row Dim r As Integer = rand.Next(0, dt.Rows.Count - 1) Dim tmpRow As MediasTagsRow = dt(r) ' Import it into the new DataTable rep.ImportRow(tmpRow) ' Remove it from the old one, to be sure not to pick it again dt.Rows.RemoveAt(r) ' Increment the counter count += 1 End While ' Return the new sub set Return rep End Function Pro’s This method is good because it doesn’t require much work to get it work fast. It is a good concept when you are working with small tables, let says less than 100 records. Con’s If you have more than 100 records, out of memory exception may occur since we are coping and duplicating rows. I would consider using a stored procedure instead.

    Read the article

  • Setting Nullable Integer to String Containing Nothing yields 0

    - by Brian MacKay
    I've been pulling my hair out over some unexpected behavior from nullable integers. If I set an Integer to Nothing, it becomes Nothing as expected. If I set an Integer? to a String that is Nothing, it becomes 0! Of course I get this whether I explicitly cast the String to Integer? or not. I realize I could work around this pretty easily but I want to know what I'm missing. Dim NullString As String = Nothing Dim NullableInt As Integer? = CType(NullString, Integer?) 'Expected NullableInt to be Nothing, but it's 0! NullableInt = Nothing 'This works -- NullableInt now contains Nothing. How is this EDIT: Previously I had my code up here so without the explicit conversion to 'Integer?' and everyone seemed to be fixated on that. I want to be clear that this is not an issue that would have been caught by Option Strict On -- check out the accepted answer. This is a quirk of the string-to-integer conversion rules which predate nullable types, but still impact them.

    Read the article

  • How do I get real integer overflows in MATLAB/Octave?

    - by marvin2k
    I'm working on a verification-tool for some VHDL-Code in MATLAB/Octave. Therefore I need data types which generate "real" overflows: intmax('int32') + 1 ans = -2147483648 Later on, it would be helpful if I can define the bit width of a variable, but that is not so important right now. When I build a C-like example, where a variable gets increased until it's smaller than zero, it spins forever and ever: test = int32(2^30); while (test > 0) test = test + int32(1); end Another approach I tried was a custom "overflow"-routine which was called every time after a number is changed. This approach was painfully slow, not practicable and not working in all cases at all. Any suggestions?

    Read the article

  • How to map (large) integer on (small in size( alphanumeric string with PHP? (Cantor?)

    - by Glooh
    Dear all, I can't figure out how to optimally do the following in PHP: In a database, I have messages with a unique ID, like 19041985. Now, I want to refer to these messages in a short-url service but not using generated hashes but by simply 'calculate' the original ID. In other words, for example: http://short.url/sYsn7 should let me calculate the message ID the visitor would like to request. To make it more obvious, I wrote the following in PHP to generate these 'alphanumeric ID versions' and of course, the other way around will let me calculate the original message ID. The question is: Is this the optimal way of doing this? I hardly think so, but can't think of anything else. $alphanumString = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'; for($i=0;$i < strlen($alphanumString);$i++) { $alphanumArray[$i] = substr($alphanumString,$i,1); } $id = 19041985; $out = ''; for($i=0;$i < strlen($id);$i++) { if(isset($alphanumString["".substr($id,$i,2).""]) && strlen($alphanumString["".substr($id,$i,2).""]) 0) { $out.=$alphanumString["".substr($id,$i,2).""]; } else { $out.=$alphanumString["".substr($id,$i,1).""]; $out.=$alphanumString["".substr($id,($i+1),1).""]; } $i++; } print $out;

    Read the article

  • How to detect padding on an integer and treat it as a string?

    - by Sirber
    I have this function to prepare variable to be used in a SQL query: function sqlize($mInput) { if (!isset($mInput)) $mInput = "null"; elseif (strtolower($mInput) == "null") { } elseif (is_numeric($mInput)) { } elseif (is_string($mInput)) { $mInput = trim($mInput); $mInput = addslashes($mInput); $mInput = '"' . $mInput . '"'; } else $mInput = "null"; return $mInput; } I have a string "0004", which is going in a "varchar field", is cought by is_numeric, and is saved as "4" and not "0004". Is there a way to detect the padding and process it as a string? Thank you!

    Read the article

  • When to address integer overflow in C

    - by Yktula
    Related question: http://stackoverflow.com/questions/199333/best-way-to-detect-integer-overflow-in-c-c In C code, should integer overflow be addressed whenever integers are added? It seems like pointers and array indexes should be checked at all. When should integer overflow be checked for? When numbers are added in C without type explicitly mentioned, or printed with printf, when will overflow occur? Is there a way to automatically detect when an integer arithmetic overflow?

    Read the article

  • CVE-2006-3744 Multiple Integer overflow vulnerabilities in ImageMagick

    - by chandan
    CVE DescriptionCVSSv2 Base ScoreComponentProduct and Resolution CVE-2006-3744 Numeric Errors vulnerability 5.1 ImageMagick Solaris 10 SPARC: 136882-03 X86: 136883-03 This notification describes vulnerabilities fixed in third-party components that are included in Sun's product distribution.Information about vulnerabilities affecting Oracle Sun products can be found on Oracle Critical Patch Updates and Security Alerts page.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >