any

How to write C function accepting (one) argument of any type

孤街浪徒 提交于 2019-12-05 05:13:34
I am implementing simple library for lists in C, and I have a problem with writing find function. I would like my function to accept any type of argument to find, both: find(my_list, 3) and find(my_list, my_int_var_to_find) . I already have information what is type of list's elements . For now I've found couple of ways dealing with this: different function with suffix for different types: int findi(void* list, int i) , int findd(void* list, double d) - but I don't like this approach, it seems like redundancy for me and an API is confusing. using union: typedef union { int i; double d; char c;

How can I do bi-directional mapping over @Any annotated property?

旧街凉风 提交于 2019-12-04 08:29:04
In this article http://www.jroller.com/eyallupu/entry/hibernate_the_any_annotation and also in this question How to use Hibernate @Any-related annotations? , how @Any annotation can be used was explained. But how can I get borrows for each DVD/VHS/BOOK? How can I do mapping definition on DVD/VHS/BOOK? I don't think this is supported and, as mentioned in the documentation: 2.4.5.2. @Any The @Any annotation defines a polymorphic association to classes from multiple tables. This type of mapping always requires more than one column. The first column holds the type of the associated entity. The

How to achieve python's any() with a custom predicate?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 10:11:59
>>> l = list(range(10)) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> if filter(lambda x: x > 10, l): ... print "foo" ... else: # the list will be empty, so bar will be printed ... print "bar" ... bar I'd like to use any() for this instead, but any() only takes one argument: the iterable. Is there a better way? Use a generator expression as that one argument: any(x > 10 for x in l) Here the predicate is in the expression side of the generator expression, but you can use any expression there, including using functions. Demo: >>> l = range(10) >>> any(x > 10 for x in l) False >>> l = range(20) >>>

how do I parse Any in dictionary using swift

谁说我不能喝 提交于 2019-12-02 11:20:40
问题 I'm not how do it parse a dictionary value which is of type . I'm able to read the key which is string and value is type of Any and has below sample values for given key ▿ 1 element ▿ 0 : 4 elements ▿ 0 : 2 elements - key : nativeName - value : Shqip ▿ 1 : 2 elements - key : iso639_2 - value : sqi ▿ 2 : 2 elements - key : name - value : Albanian ▿ 3 : 2 elements - key : iso639_1 - value : sq From above, I only need to extract "name":"Estonian" Tired looping it did not work using swift. Code:

Haskell/GHC performance of `any`/`all`

╄→гoц情女王★ 提交于 2019-12-01 19:32:55
I wrote quantification functions exists , forall , and none for Haskell's build-in [] list data type. On multiple occasions, these seemed to prove much more efficient than Prelude / Data.List s any and all . I naively suspect that this performance is due to any and all being implemented using Θ(n) folds. Since I am relatively new to Haskell, I think I must be mistaken, or that there would be a good reason for this phenomenon. From Data.Foldable : -- | Determines whether any element of the structure satisfies the predicate. any :: Foldable t => (a -> Bool) -> t a -> Bool any p = getAny #.

Python any() + generator expression

删除回忆录丶 提交于 2019-12-01 17:18:18
According to the blog post here , an any() + generator expression should run quicker than a for loop, and it seems like his reasoning makes sense. But I've tried to use this method (albeit on some other function), but it seems to take a longer time to run than an explicit for loop. def with_loop(a, b): for x in xrange(1, b): if x * a % b == 1: return True return False def with_generator(a, b): return any(x * a % b == 1 for x in xrange(1, b)) Basically the code loops through all the numbers from 1 to b to find whether the number a has a modular inverse. The times I got from running the

Which numbers are present in a vector but not in another one [duplicate]

╄→гoц情女王★ 提交于 2019-12-01 14:37:25
This question already has an answer here: How to tell what is in one vector and not another? 5 answers I guess it is a very easy question. v1 = 1:10 v2 = c(2,4,7) (none of the numbers are repeated. No need to use unique() ) I want a vector containing all the values in v1 that are not in v2. solution = c(1,3,5,6,8,9,10) I can do this using a for loop but I'm sure there are easier solution. setdiff(v1, v2) # [1] 1 3 5 6 8 9 10 Use the %in% operator with logical NOT ( ! ) to subset v1 by values not in v2 : v1[ ! v1 %in% v2 ] #[1] 1 3 5 6 8 9 10 Or you could look for non-matches of v1 in v2 (this

Which numbers are present in a vector but not in another one [duplicate]

℡╲_俬逩灬. 提交于 2019-12-01 12:34:55
问题 This question already has answers here : How to tell what is in one vector and not another? (6 answers) Closed 6 years ago . I guess it is a very easy question. v1 = 1:10 v2 = c(2,4,7) (none of the numbers are repeated. No need to use unique() ) I want a vector containing all the values in v1 that are not in v2. solution = c(1,3,5,6,8,9,10) I can do this using a for loop but I'm sure there are easier solution. 回答1: setdiff(v1, v2) # [1] 1 3 5 6 8 9 10 回答2: Use the %in% operator with logical

The parentheses rules of PostgreSQL, is there a summarized guide?

偶尔善良 提交于 2019-12-01 06:30:50
In Mathematics and many programming languages (and I think standard SQL as well), parentheses change precedence (grouping parts to be evaluated first) or to enhance readability (for human eyes). Equivalent Examples: SELECT array[1,2] @> array[1] SELECT (array[1,2]) @> array[1] SELECT array[1,2] @> (array[1]) SELECT ((array[1,2]) @> (array[1])) But SELECT 1 = ANY array[1,2] is a syntax error (!), and SELECT 1 = ANY (array[1,2]) is valid. Why? OK, because "the manual says so" . But what the logic for humans to remember all exceptions? Is there a guide about it? I do not understand why

The parentheses rules of PostgreSQL, is there a summarized guide?

无人久伴 提交于 2019-12-01 05:33:49
问题 In Mathematics and many programming languages (and I think standard SQL as well), parentheses change precedence (grouping parts to be evaluated first) or to enhance readability (for human eyes). Equivalent Examples: SELECT array[1,2] @> array[1] SELECT (array[1,2]) @> array[1] SELECT array[1,2] @> (array[1]) SELECT ((array[1,2]) @> (array[1])) But SELECT 1 = ANY array[1,2] is a syntax error (!), and SELECT 1 = ANY (array[1,2]) is valid. Why? OK, because "the manual says so". But what the