Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JuliaLang/julia
Browse files Browse the repository at this point in the history
* 'master' of github.com:JuliaLang/julia:
  using a 1-tuple instead of a Set for split with a single character
  fixing issue #214, abstract Associative type
  • Loading branch information
StefanKarpinski committed Nov 16, 2011
2 parents 3c4a5b2 + b634443 commit 720cd67
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 38 deletions.
14 changes: 13 additions & 1 deletion doc/todo
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ dot product
min,max
transpose
1d comprehension

functions needed to port computer vision project:

bsxfun
logical indexing
conv2
imread
rgb2gray
fspecial gaussian
meshgrid
histc

-------------------------------------------------------------------------------

invariance vs. covariance
Expand Down Expand Up @@ -869,5 +881,5 @@ end
* make default constructors use field types as argument types
- move more of the repl to julia

- make control-C on client while evaluating input wake up the root task
* make control-C on client while evaluating input wake up the root task
with an InterruptException if it is waiting for something.
2 changes: 1 addition & 1 deletion j/env.j
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end

## ENV: hash interface ##

type EnvHash; end
type EnvHash <: Associative; end

const ENV = EnvHash()

Expand Down
2 changes: 1 addition & 1 deletion j/multi.j
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ function start_sge_workers(n)
`echo $home/julia --worker` | qsub_cmd
out = cmd_stdout_stream(qsub_cmd)
run(qsub_cmd)
id = split(readline(out),Set('.'))[1]
id = split(readline(out),'.')[1]
println("job id is $id")
print("waiting for job to start"); flush(stdout_stream)
workers = cell(n)
Expand Down
4 changes: 3 additions & 1 deletion j/set.j
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ Set() = Set{Any}()
Set(x...) = (s = Set{Any}(); add(s, x...))
Set{T}(x::T...) = (s = Set{T}(); add(s, x...))

show{T<:Set}(s::T) = (show(T); show_comma_array(s,'(',')'))
show(s::Set) = (show(typeof(s)); show_comma_array(s,'(',')'))

isempty(s::Set) = isempty(s.hash)
length(s::Set) = length(s.hash)

has(s::Set, x) = has(s.hash, x)

get(s::Set, x, deflt) = get(s.hash, x, false)

add(s::Set, x) = (s.hash[x] = true; s)
add(s::Set, xs...) = (for x=xs; add(s, x); end; s)

Expand Down
4 changes: 2 additions & 2 deletions j/string.j
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,8 @@ function split(s::String, delims, include_empty)
end

split(s::String, delims) = split(s, delims, true)
split(s::String, c::Char) = split(s, Set(c))
split(s::String, c::Char, incl) = split(s, Set(c), incl)
split(s::String, c::Char) = split(s, (c,))
split(s::String, c::Char, incl) = split(s, (c,), incl)

function print_joined(delim, strings)
for i = 1:length(strings)
Expand Down
63 changes: 31 additions & 32 deletions j/table.j
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,35 @@ function _tablesz(i::Int)
return i<<1
end

type IdTable
_secret_table_token_ = (:BOO,)

function ref(t::Associative, key)
v = get(t, key, _secret_table_token_)
if is(v,_secret_table_token_)
throw(KeyError(key))
end
return v
end

has(t::Associative, key) = !is(get(t, key, _secret_table_token_),
_secret_table_token_)

function show(t::Associative)
if isempty(t)
print(typeof(t).name.name,"()")
else
print("{")
for (k, v) = t
show(k)
print("=>")
show(v)
print(",")
end
print("}")
end
end
type IdTable <: Associative
ht::Array{Any,1}
IdTable(sz::Int) = new(cell(2*_tablesz(sz)))
IdTable() = IdTable(0)
Expand All @@ -34,8 +62,6 @@ del(t::IdTable, key::ANY) =
del_all(t::IdTable) = (t.ht = cell(length(t.ht)); t)
_secret_table_token_ = (:BOO,)

start(t::IdTable) = 0
done(t::IdTable, i) = is(next(t,i),())
next(t::IdTable, i) = ccall(:jl_eqtable_next, Any, (Any, Uint32), t.ht, uint32(i))
Expand Down Expand Up @@ -86,7 +112,7 @@ hash(s::ByteString) = ccall(:memhash32, Uint32, (Ptr{Void}, Size), s.data, lengt
# hash table
type HashTable{K,V}
type HashTable{K,V} <: Associative
keys::Array{K,1}
vals::Array{V,1}
used::IntSet
Expand Down Expand Up @@ -254,18 +280,6 @@ next(t::HashTable, i) = ((n, nxt) = next(t.used, i);
isempty(t::HashTable) = done(t, start(t))
length(t::HashTable) = length(t.used)-length(t.deleted)
function ref(t::Union(IdTable,HashTable), key)
v = get(t, key, _secret_table_token_)
if is(v,_secret_table_token_)
throw(KeyError(key))
end
return v
end

has(t::Union(IdTable,HashTable), key) =
!is(get(t, key, _secret_table_token_),
_secret_table_token_)

function add_weak_key(t::HashTable, k, v)
if is(t.deleter, identity)
t.deleter = x->del(t, x)
Expand All @@ -281,22 +295,7 @@ function add_weak_value(t::HashTable, k, v)
t
end
function show(t::Union(IdTable,HashTable))
if isempty(t)
print(typeof(t).name.name,"()")
else
print("{")
for (k, v) = t
show(k)
print("=>")
show(v)
print(",")
end
print("}")
end
end
type WeakKeyHashTable{K,V}
type WeakKeyHashTable{K,V} <: Associative
ht::HashTable{K,V}
WeakKeyHashTable() = new(HashTable{K,V}())
Expand Down
2 changes: 2 additions & 0 deletions src/boot.j
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ end

typealias ByteString Union(ASCIIString,UTF8String)

abstract Associative

type SymbolNode
name::Symbol
typ
Expand Down

0 comments on commit 720cd67

Please sign in to comment.