equality

NSSet -member to check equality of NSValue

醉酒当歌 提交于 2019-12-23 15:03:09
问题 I have a NSSet containing many thousands of NSValue objects (wrapping CGPoints ). I would like to very quickly find if a given CGPoint value exists in the NSSet . It seems to me that the member: method of an NSSet might do the job here, except that it checks for equality using isEqual: . NSValue objects use isEqualToValue: , and so when I execute the code: [mySet member:valueToCheck]; it actually causes Xcode to crash. 1) Is there some way to use a custom equality check to make this work for

How to test order-conscious equality of hashes

大憨熊 提交于 2019-12-23 12:04:56
问题 Ruby 1.9.2 introduced order into hashes. How can I test two hashes for equality considering the order? Given: h1 = {"a"=>1, "b"=>2, "c"=>3} h2 = {"a"=>1, "c"=>3, "b"=>2} I want a comparison operator that returns false for h1 and h2 . Neither of the followings work: h1 == h2 # => true h1.eql? h2 # => true 回答1: Probably the easiest is to compare the corresponding arrays. h1.to_a == h2.to_a 回答2: You could compare the output of their keys methods: h1 = {one: 1, two: 2, three: 3} # => {:one=>1,

How does the C == operator decide whether or not two floating point values are equal?

喜夏-厌秋 提交于 2019-12-23 08:26:32
问题 Today I was tracking down why my program was getting some unexpected checksum-mismatch errors, in some code that I wrote that serializes and deserializes IEEE-754 floating-point values, in a format that includes a 32-bit checksum value (which is computed by running a CRC-type algorithm over the bytes of the floating-point array). After a bit of head-scratching, I realized the problem was the 0.0f and -0.0f have different bit-patterns (0x00000000 vs 0x00000080 (little-endian), respectively),

How does the C == operator decide whether or not two floating point values are equal?

你离开我真会死。 提交于 2019-12-23 08:26:10
问题 Today I was tracking down why my program was getting some unexpected checksum-mismatch errors, in some code that I wrote that serializes and deserializes IEEE-754 floating-point values, in a format that includes a 32-bit checksum value (which is computed by running a CRC-type algorithm over the bytes of the floating-point array). After a bit of head-scratching, I realized the problem was the 0.0f and -0.0f have different bit-patterns (0x00000000 vs 0x00000080 (little-endian), respectively),

Strange compile errors in equality: (No method 'equals(Any?): Boolean' available)

删除回忆录丶 提交于 2019-12-23 03:04:49
问题 The following code fun main(args: Array<String>) { val a = listOf('A', Pair('X', 'Y')) println(a[0] == 'B') } throws compile errors: Error:(4, 17) Unresolved reference: == Error:(4, 17) No method 'equals(Any?): Boolean' available as in the screenshot: Why do these compile errors occur? EDIT 1 : It seems it is not related with a when expression. EDIT 2 : Code snippet (Press the "run" button on the top right to compile) I need to cast manually to avoid the compile error. Using a smart cast also

Is there any Identical operator === in C like that in PHP?

筅森魡賤 提交于 2019-12-23 02:53:19
问题 In PHP , the Identical Operatpr ( === ), returns TRUE if both sides are exactly equal, and they are of the same type. Is there any similar thing in C world? 回答1: With C11 _Generic available, your question made me want to invent one. Basically you can implement this with a macro such as this: #define is_truly_equal(a, b) \ _Generic((a), \ int: _Generic((b), int: (a) == (b), default: 0), \ short: _Generic((b), short: (a) == (b), default: 0), \ default 0:) Which can get turned into an easy-to

VB.Net: test multiple values for equality?

自闭症网瘾萝莉.ら 提交于 2019-12-22 08:38:04
问题 How do you test multiple values for equality in one line? Basically I want to do if (val1 == val2 == val3 == ... valN) but in VB.Net. 回答1: If val1 = valN AndAlso val2 = valN AndAlso ... Then End If This can get cumbersome when testing more than a few values. 回答2: If you have a lot of values to test and do this very often, you could write you a helper like this: Public Function AllTheSame(ByVal ParamArray values() As Object) As Boolean For index As Integer = 1 To values.Length - 1 If values(0)

Fastest way to find out whether two ICollection<T> collections contain the same objects

拈花ヽ惹草 提交于 2019-12-22 08:02:23
问题 What is the fastest way to find out whether two ICollection<T> collections contain precisely the same entries? Brute force is clear, I was wondering if there is a more elegant method. We are using C# 2.0, so no extension methods if possible, please! Edit: the answer would be interesting both for ordered and unordered collections, and would hopefully be different for each. 回答1: use C5 http://www.itu.dk/research/c5/ ContainsAll " Check if all items in a supplied collection is in this bag

Minimization with R nloptr package - multiple equality constraints

試著忘記壹切 提交于 2019-12-22 06:27:14
问题 Is it possible to specify more than one equality constraint in nloptr function in R? The code that I am trying to run is the following: eval_f <- function( x ) { return( list( "objective" = x[3]^2+x[4]^2, "gradient" = c( 0, 0, 2*x[3], 2*x[4] ) ) ) } # constraint functions # equalities eval_g_eq <- function( x ) { constr <- c( x[1] + x[2] + x[3] - 4, x[1]^2 + x[2]^2 + x[4] - 15 ) grad <- c( c(1, 1, 1, 0), c(2*x[1], 2*x[2], 0, 1) ) return( list( "constraints"=constr, "jacobian"=grad ) ) } #

Scala, Java and equality

假装没事ソ 提交于 2019-12-22 04:58:06
问题 val filesHere = (new java.io.File(".")).listFiles val filesHere2 = (new java.io.File(".")).listFiles scala> filesHere == filesHere2 res0: Boolean = false That is quite counter intuitive. I would rather expect that filesHere and filesHere2 are equal. This is certainly due to a semantics mismatch between Java and Scala, e.g., about arrays or (files) equality. Clearly, I am missing something here! 回答1: You may want to read through here: http://ofps.oreilly.com/titles/9780596155957