Search Results

Search found 59230 results on 2370 pages for 'character set'.

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

  • java: retrieving the "canonical value" from a Set<T> where T has a custom equals()

    - by Jason S
    I have a class Foo which overrides equals() and hashCode() properly. I would like to also would like to use a HashSet<Foo> to keep track of "canonical values" e.g. I have a class that I would like to write like this, so that if I have two separate objects that are equivalent I can coalesce them into references to the same object: class Canonicalizer<T> { final private Set<T> values = new HashSet<T>(); public T findCanonicalValue(T value) { T canonical = this.values.get(value); if (canonical == null) { // not in the set, so put it there for the future this.values.add(value); return value; } else { return canonical; } } } except that Set doesn't have a "get" method that would return the actual value stored in the set, just the "contains" method that returns true or false. (I guess that it assumes that if you have an object that is equal to a separate object in the set, you don't need to retrieve the one in the set) Is there a convenient way to do this? The only other thing I can think of is to use a map and a list: class Canonicalizer<T> { // warning: neglects concurrency issues final private Map<T, Integer> valueIndex = new HashMap<T, Integer>(); final private List<T> values = new ArrayList<T>(); public T findCanonicalValue(T value) { Integer i = this.valueIndex.get(value); if (i == null) { // not in the set, so put it there for the future i = this.values.size(); this.values.add(value); this.valueIndex.put(value, i); return value; } else { // in the set return this.values.get(i); } } }

    Read the article

  • Set Theory and .NET

    - by MasterMax1313
    Recently I came across a situation where set theory and set math fit what I was doing to the letter (granted there was an easier way to accomplish what I needed - i.e. LINQ - but I didn't think of that at the time). However I didn't know of any generic set libraries. Granted IEnumerables provide some set operations (Union, etc.), but nothing like Intersection or set comparison. Can anyone point out something that fits here? Something that implements set math using a generic type?

    Read the article

  • Is it faster to loop through a Python set of number or a set of letters?

    - by Scott Bartell
    Is it faster to loop through a Python set of numbers or a Python set of letters given that each set is the exact same length and each item within each set is the same length? Why? I would think that there would be a difference because letters have more possible characters [a-zA-Z] than numbers [0-9] and therefor would be more 'random' and likely affect the hashing to some extent. numbers = set([00000,00001,00002,00003,00004,00005, ... 99999]) letters = set(['aaaaa','aaaab','aaaac','aaaad', ... 'aaabZZ']) # this is just an example, it does not actually end here for item in numbers: do_something() for item in letters: do_something() where len(numbers) == len(letters) Update: I am interested in Python's specific hashing algorithm and what happens behind the scenes with this implementation.

    Read the article

  • Python: Access members of a set

    - by emu
    Say I have a set myset of custom objects that may be equal although their references are different (a == b and a is not b). Now if I add(a) to the set, Python correctly assumes that a in myset and b in myset even though there is only len(myset) == 1 object in the set. That is clear. But is it now possible to extract the value of a somehow out from the set, using b only? Suppose that the objects are mutable and I want to change them both, having forgotten the direct reference to a. Put differently, I am looking for the myset[b] operation, which would return exactly the member a of the set. It seems to me that the type set cannot do this (faster than iterating through all its members). If so, is there at least an effective work-around?

    Read the article

  • Python: Behavior of object in set operations

    - by Josh Arenberg
    I'm trying to create a custom object that behaves properly in set operations. I've generally got it working, but I want to make sure I fully understand the implications. In particular, I'm interested in the behavior when there is additional data in the object that is not included in the equal / hash methods. It seems that in the 'intersection' operation, it returns the set of objects that are being compared to, where the 'union' operations returns the set of objects that are being compared. To illustrate: class MyObject: def __init__(self,value,meta): self.value = value self.meta = meta def __eq__(self,other): if self.value == other.value: return True else: return False def __hash__(self): return hash(self.value) a = MyObject('1','left') b = MyObject('1','right') c = MyObject('2','left') d = MyObject('2','right') e = MyObject('3','left') print a == b # True print a == c # False for i in set([a,c,e]).intersection(set([b,d])): print "%s %s" % (i.value,i.meta) #returns: #1 right #2 right for i in set([a,c,e]).union(set([b,d])): print "%s %s" % (i.value,i.meta) #returns: #1 left #3 left #2 left Is this behavior documented somewhere and deterministic? If so, what is the governing principle?

    Read the article

  • Gvim displays wrong font when set from _gvimrc, but correct font when set from menus

    - by dggoldst
    This question applies to gVim running on Windows. I have the following line in my _gvimrc set guifont=Lucida_Sans_Typewriter:h11:cANSI When gVim starts up, it strange italicizes everything! A call to :set guifont shows that things seem to have been set correctly, as it returns guifont=Lucida_Sans_Typewriter:h11:cANSI Then I manually select Edit-Select Font ... and then choose Lucida Sans Typewriter, and font size 11 and submit, the italics disappear and it looks fine. I've posted my _gvimrc for reference at http://vim.pastey.net/132157 So my questions are: Why am I getting different results from setting it manually and from _gvimrc? Is there a way to capture the command that the dialog box is sending back to the program? It might include extra commands that I'm missing.

    Read the article

  • C - How to implement Set data structure?

    - by psihodelia
    Is there any tricky way to implement a set data structure (a collection of unique values) in C? All elements in a set will be of the same type and there is a huge RAM memory. As I know, for integers it can be done really fast'N'easy using value-indexed arrays. But I'd like to have a very general Set data type. And it would be nice if a set could include itself.

    Read the article

  • C++: set of C-strings

    - by Nicholas
    I want to create one so that I could check whether a certain word is in the set using set::find However, C-strings are pointers, so the set would compare them by the pointer values by default. To function correctly, it would have to dereference them and compare the strings. I could just pass the constructor a pointer to the strcmp() function as a comparator, but this is not exactly how I want it to work. The word I might want to check could be part of a longer string, and I don't want to create a new string due to performance concerns. If there weren't for the set, I would use strncmp(a1, a2, 3) to check the first 3 letters. In fact, 3 is probably the longest it could go, so I'm fine with having the third argument constant. Is there a way to construct a set that would compare its elements by calling strncmp()? Code samples would be greatly appreciated.

    Read the article

  • AS3: Adding get/set methods to a class via prototype

    - by LiraNuna
    I'm looking for a way to extend a class via prototype by adding a get and set functions. The following code will add a function to the class' prototype: MyClass.prototype.newMethod = function(... args) { }; However I want to add both a get and set functions. I tried: MyClass.prototype.fakeProperty = get function(... args) { }; MyClass.prototype.fakeProperty = set function(... args) { }; But that seem to throw compile errors. Is this even possible? Is there some 'internal' naming convention for get/set functions? I am not looking for answers such as 'create a new class and new get/set functions there'.

    Read the article

  • how to know which special character is there in a file?

    - by Pangea
    My app needs to process text files during a batch process. Occassionally I receive a file with some special character at the end of the file. I am not sure what that special character is. Is there anyway I can find what that character is so that I can tell the other team which is producing that file. I have used mozilla's library to guess the file encoding and it says UTF-8.

    Read the article

  • How could I catch an "Unicode non-character"-warning?

    - by sid_com
    How could I catch the "Unicode non-character 0xffff is illegal for interchange"-warning? #!/usr/bin/env perl use warnings; use 5.012; use Try::Tiny; use warnings FATAL => qw(all); my $character; try { $character = "\x{ffff}"; } catch { die "---------- caught error ----------\n"; }; say "something"; Output: # Unicode non-character 0xffff is illegal for interchange at ./perl1.pl line 11.

    Read the article

  • SPUtility.SendMail and the 2048 Character Limit

    - by Damon
    We were in the middle of testing a web part responsible for gathering information from visitors to our Client's website and emailing it to someone responsible for responding to the request.  During testing, however, it was brought to our attention that the message was cutting off at 2048 characters.  Now, 2048 is one of those numbers that is usually indicative of some computational limit, but I was hopeful that Microsoft had thought through the possibility of emailing more than 2048 characters from SharePoint.  Luckily I was right. and wrong. As it turns out, SPUtility.SendMail is not limited to any specific character limit as far as I can tell.  However, each LINE of text that you send via SendMail cannot exceed 2048 characters.  Since we were sending an HTML email it was constructed entirely without line breaks, far exceeding the 2048 character limit and ultimately helping to educate me about this obscure technical limitation whose only benefit thus far is offering me something to rant about on my blog.  The fix is simple, just put in a carriage return and a line break often enough to avoid going past the 2048 character limit.  I'm sure someone can present a great technical reason for the 2048 character limit, but it seems fairly arbitrary since the "\r\n" that got appended to the string are ultimately just characters too.

    Read the article

  • Was API hooking done as needed for Stuxnet to work? I don't think so

    - by The Kaykay
    Caveat: I am a political science student and I have tried my level best to understand the technicalities; if I still sound naive please overlook that. In the Symantec report on Stuxnet, the authors say that once the worm infects the 32-bit Windows computer which has a WINCC setup on it, Stuxnet does many things and that it specifically hooks the function CreateFileA(). This function is the route which the worm uses to actually infect the .s7p project files that are used to program the PLCs. ie when the PLC programmer opens a file with .s7p the control transfers to the hooked function CreateFileA_hook() instead of CreateFileA(). Once Stuxnet gains the control it covertly inserts code blocks into the PLC without the programmers knowledge and hides it from his view. However, it should be noted that there is also one more function called CreateFileW() which does the same task as CreateFileA() but both work on different character sets. CreateFileA works with ASCII character set and CreateFileW works with wide characters or Unicode character set. Farsi (the language of the Iranians) is a language that needs unicode character set and not ASCII Characters. I'm assuming that the developers of any famous commercial software (for ex. WinCC) that will be sold in many countries will take 'Localization' and/or 'Internationalization' into consideration while it is being developed in order to make the product fail-safe ie. the software developers would use UNICODE while compiling their code and not just 'ASCII'. Thus, I think that CreateFileW() would have been invoked on a WINCC system in Iran instead of CreateFileA(). Do you agree? My question is: If Stuxnet has hooked only the function CreateFileA() then based on the above assumption there is a significant chance that it did not work at all? I think my doubt will get clarified if: my assumption is proved wrong, or the Symantec report is proved incorrect. Please help me clarify this doubt. Note: I had posted this question on the general stackexchange website and did not get appropriate responses that I was looking for so I'm posting it here.

    Read the article

  • Character Jump Control

    - by Abdullah Sorathia
    I would like to know how can I control the jump movement of a character in Unity3D. Basically I am trying to program the jump in such a way that while a jump is in progress the character is allowed to move either left or right in mid-air when the corresponding keys are pressed. With my script the character will correctly move to the left when, for example, the left key is pressed, but when the right key is pressed afterwards, the character moves to the right before the movement to the left is completed. Following is the script: void Update () { if(touchingPlatform && Input.GetButtonDown("Jump")){ rigidbody.AddForce(jumpVelocity, ForceMode.VelocityChange); touchingPlatform = false; isJump=true; } //left & right movement Vector3 moveDir = Vector3.zero; if(Input.GetKey ("right")||Input.GetKey ("left")){ moveDir.x = Input.GetAxis("Horizontal"); // get result of AD keys in X if(ShipCurrentSpeed==0) { transform.position += moveDir * 3f * Time.deltaTime; }else if(ShipCurrentSpeed<=15) { transform.position += moveDir * ShipCurrentSpeed * 2f * Time.deltaTime; }else { transform.position += moveDir * 30f * Time.deltaTime; } }

    Read the article

  • Index Check and Correct Character Display in a Console Hangman Game for Java

    - by Jen
    I have this problem wherein, I can not display the correct characters given by the character. Here's what I meant: String words, in; String replaced_words; Scanner s = new Scanner (System.in); System.out.println("Enter a line of words basing on an event, verse, place or a name of a person."); words = s.nextLine(); System.out.println("The words you just placed are now accepted."); //using char array method, we tried to place the words into a characters array. char [] c = words.toCharArray(); // we need to replace the replaced_words = words.replace(' ', '_').replaceAll("[^\\-]", "-"); for (int i = 0; i < replaced_words.length(); i++) { System.out.print(replaced_words.charAt(i) + " "); } System.out.println("Now, please input a character, guessing the words you just placed."); in = s.nextLine(); in that code, want that the user, when types a word (or should it be character?), any of the correct character the user inputs will be displayed, and changes the hyphen to it...(more like the hangman series of games). How can I achieve this?

    Read the article

  • SET game odds simulation (MATLAB)

    - by yuk
    Here is an interesting problem for your weekend. :) I recently find the great card came - SET. Briefly, there are 81 cards with the four features: symbol (oval, squiggle or diamond), color (red, purple or green), number (one, two or three) or shading (solid, striped or open). The task is to find (from selected 12 cards) a SET of 3 cards, in which each of the four features is either all the same on each card or all different on each card (no 2+1 combination). In my free time I've decided to code it in MATLAB to find a solution and to estimate odds of having a set in randomly selected cards. Here is the code: %% initialization K = 12; % cards to draw NF = 4; % number of features (usually 3 or 4) setallcards = unique(nchoosek(repmat(1:3,1,NF),NF),'rows'); % all cards: rows - cards, columns - features setallcomb = nchoosek(1:K,3); % index of all combinations of K cards by 3 %% test tic NIter=1e2; % number of test iterations setexists = 0; % test results holder % C = progress('init'); % if you have progress function from FileExchange for d = 1:NIter % C = progress(C,d/NIter); % cards for current test setdrawncardidx = randi(size(setallcards,1),K,1); setdrawncards = setallcards(setdrawncardidx,:); % find all sets in current test iteration for setcombidx = 1:size(setallcomb,1) setcomb = setdrawncards(setallcomb(setcombidx,:),:); if all(arrayfun(@(x) numel(unique(setcomb(:,x))), 1:NF)~=2) % test one combination setexists = setexists + 1; break % to find only the first set end end end fprintf('Set:NoSet = %g:%g = %g:1\n', setexists, NIter-setexists, setexists/(NIter-setexists)) toc 100-1000 iterations are fast, but be careful with more. One million iterations takes about 15 hours on my home computer. Anyway, with 12 cards and 4 features I've got around 13:1 of having a set. This is actually a problem. The instruction book said this number should be 33:1. And it was recently confirmed by Peter Norvig. He provides the Python code, but I didn't test it. So can you find an error?

    Read the article

  • Whats the best to way convert a set of Java objects to another set of objects?

    - by HDave
    Basic Java question here from a real newbie. I have a set of Java objects (of class "MyClass") that implement a certain interface (Interface "MyIfc"). I have a set of these objects stored in a private variable in my class that is declared as follows: protected Set<MyClass> stuff = new HashSet<MyClass>(); I need to provide a public method that returns this set as a collection of objects of type "MyIfc". public Collection<MyIfc> getMyStuff() {...} How do I do the conversion? The following line gives me an error that it can't do the conversion. I would have guessed the compiler knew that objects of class MyClass implemented MyIfc and therefore would have handled it. Collection<MyIfc> newstuff = stuff; Any enlightenment is appreciated.

    Read the article

  • SpriteFont Exception, no such character?

    - by Michal Bozydar Pawlowski
    I have such spriteFont: <?xml version="1.0" encoding="utf-8"?> <!-- This file contains an xml description of a font, and will be read by the XNA Framework Content Pipeline. Follow the comments to customize the appearance of the font in your game, and to change the characters which are available to draw with. --> <XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics"> <Asset Type="Graphics:FontDescription"> <!-- Modify this string to change the font that will be imported. --> <FontName>Segoe UI</FontName> <!-- Size is a float value, measured in points. Modify this value to change the size of the font. --> <Size>20</Size> <!-- Spacing is a float value, measured in pixels. Modify this value to change the amount of spacing in between characters. --> <Spacing>0</Spacing> <!-- UseKerning controls the layout of the font. If this value is true, kerning information will be used when placing characters. --> <UseKerning>true</UseKerning> <!-- Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic", and "Bold, Italic", and are case sensitive. --> <Style>Regular</Style> <!-- If you uncomment this line, the default character will be substituted if you draw or measure text that contains characters which were not included in the font. --> <!-- <DefaultCharacter>*</DefaultCharacter> --> <!-- CharacterRegions control what letters are available in the font. Every character from Start to End will be built and made available for drawing. The default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin character set. The characters are ordered according to the Unicode standard. See the documentation for more information. --> <CharacterRegions> <CharacterRegion> <Start>&#09;</Start> <End>&#09;</End> </CharacterRegion> <CharacterRegion> <Start>&#32;</Start> <End>&#1200;</End> </CharacterRegion> </CharacterRegions> </Asset> </XnaContent> It has the character regions (32-1200) And I get this exception: A first chance exception of type 'System.ArgumentException' occurred in Microsoft.Xna.Framework.Graphics.ni.dll The character '?' (0x0441) is not available in this SpriteFont. If applicable, adjust the font's start and end CharacterRegions to include this character. Parameter name: character Why? I'm drawing the string like this: spriteBatch.DrawString(font24, zasadyText, zasadyTextPos, kolorCzcionki1, -0.05f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f) I even changed the spriteFont to cyrillic: <CharacterRegions> <CharacterRegion> <Start>&#09;</Start> <End>&#09;</End> </CharacterRegion> <CharacterRegion> <Start>&#0032;</Start> <End>&#0383;</End> </CharacterRegion> <CharacterRegion> <Start>&#1040;</Start> <End>&#1111;</End> </CharacterRegion> </CharacterRegions> </Asset> </XnaContent> and it still doesn't work. I got the (0x441 = char) exception -- EDIT -- Ok, I got the solution. It was a letter mistake in language. I had this: if (jezyk == "ru_RU") { font14 = Content.Load<SpriteFont>("ru_font14"); font24 = Content.Load<SpriteFont>("ru_font24"); font12 = Content.Load<SpriteFont>("ru_czcionkaFloty"); font10 = Content.Load<SpriteFont>("ru_font10"); font28 = Content.Load<SpriteFont>("ru_font28"); font20 = Content.Load<SpriteFont>("ru_font20"); } else { font14 = Content.Load<SpriteFont>("font14"); font24 = Content.Load<SpriteFont>("font24"); font12 = Content.Load<SpriteFont>("czcionkaFloty"); font10 = Content.Load<SpriteFont>("font10"); font28 = Content.Load<SpriteFont>("font28"); font20 = Content.Load<SpriteFont>("font20"); } and there should be not "ru_RU" but "ru-RU" I have no idea. I changed the spriteFont to cyrillic: <CharacterRegions> <CharacterRegion> <Start>&#09;</Start> <End>&#09;</End> </CharacterRegion> <CharacterRegion> <Start>&#0032;</Start> <End>&#0383;</End> </CharacterRegion> <CharacterRegion> <Start>&#1040;</Start> <End>&#1111;</End> </CharacterRegion> </CharacterRegions> </Asset> </XnaContent> and it still doesn't work. I got the (0x441 = char) exception

    Read the article

  • What is use of universal character names in identifiers in C++

    - by Jan Hudec
    The C++ standard (I noticed it in the new one, but it did already exist in C++03) specifies universal character names, written as \uNNNN and \UNNNNNNNN and representing the characters with unicode codepoints NNNN/NNNNNNNN. This is useful with string literals, especially since explicitly UTF-8, UTF-16 and UCS-4 string literals are also defined. However, the universal character literals are also allowed in identifiers. What is the motivation behind that? The syntax is obviously totally unreadable, the identifiers may be mangled for the linker and it's not like there was any standard function to retrieve symbols by name anyway. So why would anybody actually use an identifier with universal character literals in it? Edit: Since it actually existed in C++03 already, additional question would be whether you actually saw a code that used it?

    Read the article

  • Child object free movement on Parent object

    - by The415
    Just to be straightforward, I am completely new to many aspects of coding and am searching for different specs and guidelines to aid me on my journey to crafting a wonderful game in Epic Games' Unreal Engine 4. Okay, I know upon viewing this, some may have little to no clue what I mean, so I'll put it like this to explain what I mean : Imagine a third person game with a simple model of a character. Now, say I have an object as a torso of a character in a game. Now Say I have an object as a head of the character. How could I keep the head as a child of the torso, but at the same time, allow it to move with the camera angle.

    Read the article

  • What is use of universal character names in identifiers in C++11

    - by Jan Hudec
    The new C++ standard specifies universal character names, written as \uNNNN and \UNNNNNNNN and representing the characters with unicode codepoints NNNN/NNNNNNNN. This is useful with string literals, especially since explicitly UTF-8, UTF-16 and UCS-4 string literals are also defined. However, the universal character literals are also allowed in identifiers. What is the motivation behind that? The syntax is obviously totally unreadable, the identifiers may be mangled for the linker and it's not like there was any standard function to retrieve symbols by name anyway. So why would anybody actually use an identifier with universal character literals in it?

    Read the article

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